类星体构建后无法连接到后端

Can't connect to backend after quasar build

我有一个用 quasar 制作的项目,我有一个代理将应用程序上的调用映射到我的后端 API,但是当它使用 quasar build 构建时,它会生成 dist 文件夹,用于测试我使用服务器,如果它可以工作但应用程序进行的调用不起作用

这应该调用 http://localhost:8080/getCategories

这是代理配置文件:

proxyTable: {
  '/api': {
    target: 'http://localhost:8080/',
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  }
}

当我在开发服务器上尝试时,开发服务器 运行 在 8081

我不知道是否必须更改 API 调用,我所做的所有调用都像 this.$http.get('/api/getCategories') 示例。

不知道我解释清楚没有,希望有人能帮忙,谢谢!

已解决

我已经解决了,不知道这是否是正确的方法,将尝试为其他可能有同样问题的人解释。

首先,我从 config/index.js 中删除了 proxyTable,然后添加了一个环境,config/dev.env.js 中的一个如下所示:

var merge = require('webpack-merge')
var prodEnv = require('./prod.env')

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  API: "'http://localhost:8080'"
})

还有一个 config/prov.env.js 看起来像这样:

module.exports = {
  NODE_ENV: '"production"',
  API: "'http://my-website.com:8080'"
}

然后我使用 VueResource 的所有 AJAX 调用如下所示:

this.$http.get(`${process.env.API}/path/`)
    .then(response => response.json(), console.log)
            .then(response => {
                 console.log(response)
            })

完全适合我,希望有人觉得这有用!