我使用NuxtJ和ssr。用于使用axios
和代理模块获取数据im。'@nuxtjs/proxy'
,
modules: [
'@nuxtjs/proxy'
],
axios: {
proxy: true
},
proxy: {
'/api/v1/': {
target: 'https://dev.***.io/'
}
},
dev.server用basic auth关闭(在挂载()中我没有问题)
我如何为ssr (asyncData()
,或异步fetch()
)获取数据以使其全部工作。
我在尝试官方文件
async fetch() {
this.ps = await axios.get('/api/v1/main').then(res => res.data)
}
但是得到一个错误:client.js?06a0:57 Error in fetch(): Error: connect ECONNREFUSED 127.0.0.1:80
Img尝试asyncData,但有相同的错误。需要帮助!
发布于 2022-02-28 11:26:36
你需要重写路线,就像这样:
'/api/v1/': {
target: 'https://dev.***.io/',
pathRewrite: { '^/api/v1/': '' },
}
https://stackoverflow.com/questions/71279564
复制相似问题