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部署到開發環境下的跨域解決:vue

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

 location /api {
        rewrite ^/api/(.*)$ /$1 break;
            proxy_pass http://testw.haier.com;
        }
相關文章
相關標籤/搜索