vue-cli (旧版本) axios请求跨域
在config文件夹index.js中proxyTable 里配置
proxyTable: {
'/api': {
target: 'http://localhost:8002/', // 请求接口域名
// secure: false, //https接口,需要配置这个参数
changeOrigin: true,
pathRewrite: {
'^/api': '/api' //rewrite重定向
}
}
}
**或者**
proxyTable: {
'/api': {
target: 'http://localhost:8002/api', // 请求接口域名
// secure: false, //https接口,需要配置这个参数
changeOrigin: true,
pathRewrite: {
'^/api': '' //rewrite重定向
}
}
}
配置后需重新启动项目
’ /api ’ 会代理到 ’ http://localhost:8002/ ’
axios请求
this.axios.post('/api/task/comment_custom',arr).then((res)=>{
this.test=res.message;
})