Vue开发环境中解决跨域问题

1、vue.config.js中配置proxy

module.exports = {
    publicPath: '/',
    outputDir: "dist",
    devServer: {
        proxy: {
            '/api': {
                target: 'http://m.renyiwenzhen.com/',
                changeOrigin: true,
                pathRewrite: {
                    "/api": ''
                }
            }
        }
    }
};

 2、组件里面请求,补全接口地址

get(){
        this.axios.get('api/xcx_ajax.php?action=babylist').then(res =>{
                 console.log(res);
         }
}

3、成功

 

刚干前端没多久,欢迎指正。

 
posted @ 2019-12-26 14:06  一碗白开水。  阅读(848)  评论(1)    收藏  举报