显示报错
在vue.config.js中添加
devServer: {
proxy: {
'/api': {
//代理api
target: '', // 代理接口(注意只要域名就够了)
changeOrigin: true, //是否跨域
ws: true, // proxy websockets
pathRewrite: {
//重写路径
'^/api': '' //代理路径
}
}
}
}
然后在main.js
文件,配置一下axios.defaults.baseURL = '/api'
正常在组件中使用axios请求数据,最后重启项目就可以了