配置代理:
proxy: {
'/api': {
target: 'http://localhost:8000', //跨域请求的公共地址
ws: false, //也可以忽略不写,不写不会影响跨域
changeOrigin: true, //是否开启跨域,值为 true 就是开启, false 不开启
pathRewrite: {
'^/api': '' //注册全局路径, 但是在你请求的时候前面需要加上 /api
}
}
},
发送请求:
axios.get('/api/artic/4').then(res=>{
console.log(res);
})