【发布时间】:2019-10-27 14:28:24
【问题描述】:
我一直在搜索和阅读有关此主题的文档,但我无法让它发挥作用。 https://cli.vuejs.org/config/#devserver-proxy
我通过命令正常地制作了我的 Vue.js 应用程序
vue create my-app
所以我通过命令运行应用程序
npm run serve
在http://localhost:8080/。非常标准的东西。
但是我的应用需要一个 PHP 后端,它在 https://localhost/ 运行 所以我在根目录下的 vue.confic.js 文件中设置了代理设置。
vue.confic.js 文件内容:
module.exports = {
devServer: {
proxy: {
'^/api': {
target: 'https://localhost/',
ws: true,
changeOrigin: true
}
}
}
};
我正在尝试让 axios 调用地址上的脚本
https://localhost/test.php
axios调用是
mounted() {
this.$axios.get('api/test.php', {})
.then(response => { console.log(response.data) })
.catch(error => { console.log(error) });
},
但由于某种原因,我无法弄清楚我仍然得到了
GET http://localhost:8080/api/test.php 404 (Not Found)
提前谢谢你。任何提示我都会很高兴。
【问题讨论】:
-
api在哪个端口上运行?