vue dev开发环境跨域和build生产环境跨域问题解决


dev开发时解决请求跨域问题:config-index.js 配置代理
dev: { env: require('./dev.env'), port: 8082, assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/api': { target: 'http://testw.haier.com', //后端接口地址 changeOrigin: true, //是否允许跨越 pathRewrite: { '^/api': '', //重写, } } },

 

vue单页请求路径写法 
this.$http.post('/api/interaction-comment/getCommentList', parms).then((response) => { response = response.data; console.log(response.data) if (response.isSuccess === true) { console.log("输出") this.currentTotal = response.data.entityCount; this.tableData = response.data.entities; } }); }

  

npm run build部署到开发环境下的跨域解决:

在nginx-1.12.1\conf 配置文件中增加:

 location /api {
        rewrite ^/api/(.*)$ /$1 break;
            proxy_pass http://testw.haier.com;
        }

  

转载于:https://www.cnblogs.com/hanguidong/p/10365083.html

你可能感兴趣的:(vue dev开发环境跨域和build生产环境跨域问题解决)