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