Vue axios調用第三方接口跨域解決


1.

在config目錄下index.js文件中設置proxyTable:

proxyTable: {
      '/v1': { target: 'https://api.douban.com', changeOrigin: true, pathRewrite: { // /v1將代表target/v1 '^/v1': '/v1' } } }

2.0 

2.

因為在新版的vue-cli的package.json中webpack-dev-server沒有設置--open,所以打開package.json文件在”scripts”屬性中的”dev”屬性中手動添加--open,如下代碼所示:

"scripts": { "dev": "webpack-dev-server --open --inline --progress --config build/webpack.dev.conf.js", "start": "npm run dev", "build": "node build/build.js" },

3.0 

3.

      axios
        .get(
          "/v1/getServiceInfo?xxxxxx" ) .then(res => { console.log(res.data) })





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM