代理服务器
找到
config文件夹下的index.js文件-
添加代理相关代码
proxyTable: { '/api': { // 名字 target: 'https://m.juanpi.com/index/getMenu?select=1_1', // 目标地址 changeOrigin: true, pathRewrite: { '^/api': '/' // 名字 } }, } 重启
npm run dev-
正常请求
this.axios.get('api').then(res => { console.log(res.data); });
JSONP请求
-
安装jsonp模块
$ npm install --save jsonp -
在
main.js引入import jsonp from 'jsonp' Vue.prototype.jsonp = jsonp -
编写代码发起网络请求
this.jsonp('https://shop.juanpi.com/gsort?key=zuixinzhekou&type=1&zhouyi_ids=p8_c4_l1_18_51_5&machining=hotcoupon&page=1&rows=10&dtype=JSONP&cm=1&cm_channel=1&callback=gsort_callback', (err, data) => { console.log(err); console.log(data); })