nuxt/http和nuxjs/proxy使用另一个api创建错误
我试图在一个静态生成的Nuxt站点上获取内容,阅读文章以离开axios,而是使用 我还希望在开发过程中避免代理错误,因此我将nuxt.config.js设置为:nuxt/http和nuxjs/proxy使用另一个api创建错误,proxy,fetch,nuxt.js,Proxy,Fetch,Nuxt.js,我试图在一个静态生成的Nuxt站点上获取内容,阅读文章以离开axios,而是使用 我还希望在开发过程中避免代理错误,因此我将nuxt.config.js设置为: http: { proxy: true }, proxy: { '/api/': { target: 'https://www.myapi.com', pathRewrite: { '^/api/': '' } } }, 案例1 async fetch() {
http: {
proxy: true
},
proxy: {
'/api/': {
target: 'https://www.myapi.com',
pathRewrite: { '^/api/': '' }
}
},
案例1
async fetch() {
const apiresults = await this.$http.$get(`/api/`)
this.apiresults = apiresults
}
结果:在路线导航中获取内容,但在登录、页面刷新或静态生成时不获取内容。
我得到一个错误,其中,除其他行外,表示:
[Symbol(Response internals)]: {
url: 'http://i-have-another-api-not-related.com/api/',
status: 404,
statusText: 'Not Found'
如您所见,还有另一个api从其他地方获取数据,而nuxtjs/proxy似乎在url的末尾添加了“/api/”。这两件事是分开的,所以我不明白为什么会发生
案例2
async fetch() {
const apiresults = await this.$http.$get(`https://www.myapi.com`)
this.apiresults = apiresults
}
结果:如果直接复制url,则仅在登录或页面刷新时加载数据,在页面更改/路由时不加载数据(CORS错误)
为什么另一个api会卷入其中?
我如何才能在着陆/刷新和路由方面都获得数据工作而不出现任何问题?
谢谢