Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

NuxtJS部署后,切换界面后提示控制台报504的错误,求指导

问题

在使用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 接口测试截图

image.png

正常请求控制台输出

image.png

疑惑点

项目在本地跑的时候,没任何问题,只要上服务器运行就会出现这个问题,proxy做代理的时候,浏览器的请求地址也是localhost+端口的形式,请大佬指点一下

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...