vue 跨域
vue跨域参考链接
1、打开config/index.js,在proxyTable中添写如下代码:
proxyTable: {
'/api': { //使用"/api"来代替"http://f.apiplus.c"
target: 'http://f.apiplus.cn', //源地址
changeOrigin: true, //改变源
pathRewrite: {
'^/api': 'http://f.apiplus.cn' //路径重写 (经测试:这里不为空或'/’,得写域名(列如:http://f.apiplus.cn))
}
}
}
2、使用axios请求数据时直接使用“/api”(对应步骤1中的//路径重写):
getData () {
axios.get('/api/bj11x5.json', function (res) {
console.log(res)
})