我正在尝试通过我的nuxtjs站点访问Feedly。为此,我使用nuxt-公理模块。
首先,我注意到Feedly指令:
我们提供了一个标准的OAuth 2.0身份验证模块,它为应用程序提供了OAuth访问令牌。大多数端点都期望有授权头。 $ curl -H‘授权: OAuth您的开发人员访问令牌’https://cloud.feedly.com/v3/profile
现在,我尝试将其集成到nuxtjs-axios中。
首先,我设置了我的nuxt-config.js文件:
export default {
...
plugins: [{ src: `~/plugins/axios.js` }],
modules: [
'@nuxtjs/axios',
],
axios: {
credentials: true
},
env: {
FEEDLY_ACCESS_TOKEN:
[MY_FEEDLY_DEV_ACCESS_TOKEN]
},
...
}然后在axios.js文件夹中创建一个plugins插件(导入到我前面提到的nuxt-config.js文件中):
export default function({ $axios }) {
$axios.setHeader('Authorization', `OAuth ${process.env.FEEDLY_ACCESS_TOKEN}`)
}问题是,我不知道我应该在axios.js插件文件中放什么--或者即使这样做是正确的。我所做的只是在黑暗中捅了一针而已。
因此,我的问题是,如何使用nuxtjs-axios模块将Feedly实现为nuxtjs?
谢谢。
发布于 2020-01-03 00:50:03
使用拦截器:
// Add a request interceptor
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
}, function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
});https://github.com/axios/axios/blob/master/README.md#interceptors
发布于 2021-06-14 13:58:20
我对nuxt文档的理解是,plugin.axios文件用于添加“默认”行为(axios帮助程序:https://axios.nuxtjs.org/helpers/)。
我认为您的插件是正确的(如果令牌是您唯一需要添加到您的标题)。
启用nuxt-axios后,现在可以使用this.$axios.get/post.。
您是否尝试过使用以下方法运行组件:
this.$axios.get('**feedly_url_api_url_here**').then(response)....https://stackoverflow.com/questions/59042735
复制相似问题