服务器端口为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)
}
)
},
控制台显示代理没有起作用:
你用法 错了吧
试试下面的,不行的话,去掉 /api前面的/
mounted() {
axios.get("/api/index_category").then(
response=>{
console.log(response.data)
},error=>{
console.log(error)
}
)
},
大佬带带我😭😭😭