在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ vue跨域請(qǐng)求proxyTable問(wèn)題

vue跨域請(qǐng)求proxyTable問(wèn)題

這個(gè)是config中index.js添加proxyTable

 proxyTable: {
       '/research': {
         target: 'https://api.shenjian.io/?appid=c36a22e564a2954e&keyword=a&pageNo=1&pageSize=20',
 //目標(biāo)接口域名
        changeOrigin: true,  //是否跨域
         pathRewrite: {
           '^/research': '/c'   //重寫(xiě)接口
         }
       }
     }
           

api中index.js添加接口

export default {
    songsearch: '/research'
  }

store中調(diào)用ajax函數(shù)

  mutations: {
    changeKeyword(state, x) {
      ajax(require.songsearch)
    }
   }

ajax

const ajax = function (url) {
  return new Promise(function (resolve, reject) {
    axios.get(url).then(res => {
      resolve(res);
    }).catch(reject);
  });
}

這個(gè)是結(jié)果
圖片描述

剛開(kāi)始學(xué)習(xí)vue,想做一個(gè)web播放器而且已經(jīng)拿到api,但是axios請(qǐng)求需要跨域,所以用proxyTable的方法進(jìn)行代理,但是請(qǐng)求地址變成了端口號(hào),為什么?

回答
編輯回答
傻丟丟

你這樣配置完,訪問(wèn)到的接口是 https://api.shenjian.io/?appi... 這樣肯定要報(bào)404啊。
還有就是在瀏覽器中,雖然你看到的是localhost:8080,但其實(shí)已經(jīng)經(jīng)過(guò)代理轉(zhuǎn)發(fā)到你要請(qǐng)求的target了

2017年3月27日 18:26