代理服務(wù)器
找到
config
文件夾下的index.js
文件-
添加代理相關(guān)代碼
proxyTable: { '/api': { // 名字 target: 'https://m.juanpi.com/index/getMenu?select=1_1', // 目標(biāo)地址 changeOrigin: true, pathRewrite: { '^/api': '/' // 名字 } }, }
重啟
npm run dev
-
正常請(qǐng)求
this.axios.get('api').then(res => { console.log(res.data); });
JSONP請(qǐng)求
-
安裝jsonp模塊
$ npm install --save jsonp
-
在
main.js
引入import jsonp from 'jsonp' Vue.prototype.jsonp = jsonp
-
編寫代碼發(fā)起網(wǎng)絡(luò)請(qǐng)求
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); })
?