npm run dev 在本地调试出现跨域问题
在localhost:8080调试时会出现跨域问题,如图:
// # 项目\config\index.js
dev: {// PathsassetsSubDirectory: 'static',assetsPublicPath: '/',// # 配置代理proxyTable: {'/apis': {target: 'http://dev.daishutijian.com',changeOrigin: true,pathRewrite: {'^/apis': ''}}},// Various Dev Server settingshost: '0.0.0.0', // can be overwritten by process.env.HOSTport: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined...
},
复制代码
将 http://dev.daishutijian.com
映射为^/apis
// # 发送请求
const API_PATH = "apis/apps/api/";
function getOrderList(vm) {let url = API_PATH + 'user/order_list';// # http://dev.daishutijian.com/apps/api/user/order_listreturn new Promise((resolve, reject) => {Vue.http.get(url, {emulateJSON: true},).then((res) => {resolve(res.data);}).catch((res) => {console.log('warn');})})
}
复制代码
设置代理,请求成功