在vue.config.js文件中添加
module.exports = {
devServer: {
open: true,
host: 'localhost',
port: 8000,
https: false,
//以上的ip和端口是我们本机的;下面为需要跨域的
proxy: { //配置跨域,proxy的意思就是代理下边的/api,也就是说如果在请求中是以/api开头的都需要进行代理。
'/api': {
target: 'http://127.0.0.1:8000/api/', //填写真实的后台接口
ws: true,
changOrigin: true, //允许跨域
pathRewrite: {
'^/api': '' //请求的时候使用这个api就可以
}
}
}
}
}