vue3-cli配置跨域
1.在vue.config.js中配置
module.exports = { devServer: { proxy: { '/api': { target: 'http://22.163.72.64', //跨越的对应服务器地址 changeOrigin: true, //允许跨域 ws: true, pathRewrite: { '^/api': '' } } } } }
2.发送请求
axios.get("api/test/login")
.then((res) => {
console.log(res)
})
// 相当于
axios.get("http://22.163.72.64/test/login")
.then((res) => {
console.log(res)
})