vue-cli3中的跨域配置

在vue.config.js中配置

module.exports = {
    devServer: {
        proxy: {
            '/api': {
                target: 'http://localhost:3000',
                changeOrigin: true,
                pathRewrite: {
                    '/api': ''
                }
            }
        }
    
    },

}

修改完这个文件记得重启你的项目
在使用的时候(这里使用axios举例):
比如要访问的是 http://localhost:3000/interface1 这个接口

this.$axios.get('/api/interface1').then(res->{
    console.log(res);
})

评论

暂无评论