【发布时间】:2019-08-22 00:48:27
【问题描述】:
我在发出客户请求时遇到问题。
我已按照 Nuxt.js 和 Axios 上的文档进行操作,但似乎仍然无法正常工作。也许我错过了什么..
我的 Vue 组件调用 vuex 操作:
methods: {
open() {
this.$store.dispatch('events/getEventAlbum');
}
}
vuex中的action:
export const actions = {
async getEventAlbum(store) {
console.log('album action');
const response = await Axios.get(url + '/photos?&sign=' + isSigned + '&photo-host=' + photoHost);
store.commit('storeEventAlbum', response.data.results);
}
};
还有我的 nuxt.js.config
modules: [
'@nuxtjs/axios',
'@nuxtjs/proxy'
],
axios: {
proxy: true
},
proxy: {
'/api/': {
target: 'https://api.example.com/',
pathRewrite: { '^/api/': '' }
}
}
谁能帮忙?
【问题讨论】:
-
这将是您的 api 阻止请求。您在控制台中遇到的 cors 错误是什么?你用的是什么类型的api?
-
嗨@Andrew1325,这是一个 RESTful API,我收到 No 'Access-Control-Allow-Origin' 标头 错误。跨度>
-
你的 api 是 express (node.js) api吗?
-
@Andrew1325 ,是的,Nuxt.js 是建立在 Node & Express 之上的
-
@Manu 不,Nuxt 构建在 Vue.js 之上,显然是 Node.js。 Express 只是一个集成。