一.設置config/index.js || proxyTable添加
proxyTable: { '/api': { target: 'http://192.168.48.239:8080/ydzl', changeOrigin: true, pathRewrite: { '^/api': '' } }二.mian.js 添加vue全局屬性
Vue.prototype.HOST = '/api'
三.如果是post的話
1.修改數據格式
transformRequest: [function (data) { // Do whatever you want to transform the data let ret = '' for (let it in data) { ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&' } return ret }],2.修改請求頭
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }以上所述是小編給大家介紹的Vue Ajax跨域請求實例詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!
新聞熱點
疑難解答
圖片精選