vue3脚手架设置跨越

Posted on 2020-05-07 20:59  张雪冬前端学习园地  阅读(552)  评论(0编辑  收藏  举报

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)
})