服务器端口为4000,postman测试没有问题:
vue.config.js如下:
module.exports = {
devServer: {
host: 'localhost',
port: 8080,
proxy: {
'/api': {
target: 'http://localhost:4000',// 要跨域的域名
changeOrigin: true, // 是否开启跨域
},
}
}
}
在App.vue中测试代理:
mounted() {
axios.get("http://localhost:8080/api/index_category").then(
response=>{
console.log(response.data)
},error=>{
console.log(error)
}
)
},
控制台显示代理没有起作用:
奇怪的是我在一个新的vue项目中使用同样的方法测试没有问题:
难道说还要改啥其它配置嘛,有没有遇到过的赐教