问题
在使用nuxtJS
做Vue的SSR之后,本地编译及访问无任何问题,在部署到服务端之后,首次访问无任何问题,只要切换界面,就会提示 net::ERR_CONNECTION_REFUSED
。
JS代码
export default {
async asyncData({ $axios }) {
const result = await $axios.post("/api/article/list", {
pageSize: 10,
pageNo: 1
});
if (result) {
this.list = result;
}
}
}
nuxt.config.js 配置如下
export default {
mode: "universal",
telemetry: false,
/*
** Global CSS
*/
css: [
"assets/style.scss"
],
/*
** Plugins to load before mounting the App
*/
plugins: [
{
src: "~/plugins/api.js"
},
{
src: "~/plugins/dayJS.js"
}
],
/*
** Nuxt.js dev-modules
*/
buildModules: [],
/*
** Nuxt.js modules
*/
modules: [
"@nuxtjs/proxy",
"@nuxtjs/axios"
],
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
}
},
proxy: {
"/api": {
target: "https://xxx.xxx.com/api",
changeOrigin: true,
pathRewrite: {
"^/api": ""
}
}
}
}
postman 接口测试截图
正常请求控制台输出
疑惑点
项目在本地跑的时候,没任何问题,只要上服务器运行就会出现这个问题,proxy做代理的时候,浏览器的请求地址也是localhost+端口的形式,请大佬指点一下
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…