vue 本地調試跨域---帶cookies(axios)


cookise跨域第二期之便捷優雅的本地調試(axios)

1、打開config/index.js,在proxyTable中添寫如下代碼:

proxyTable: {
      '/agent': {  //使用"/agent"來代替源地址
        target: 'https://datacloudtest.mncats365.com', //想要訪問的地址
        secure: true,//如果是https請設置為true
        changeOrigin: true, //改變源
        pathRewrite: {
          '^/agent': 'http://localhost:8081' //本地路徑
        }
      }
    },

2、使用axios請求數據時直接使用“/agent”:

如果沒有自行封裝axios,就直接在main.js中引入

 

import axios from 'axios'

Vue.prototype.$axios=axios

 

使用

this.$axios.get('/agent/web/followMac/getFollowMacList').then(res => {
          console.log(res)
        }).catch(error => {
          console.log(error)
        })

如果自行封裝axios——直接寫

http.get('/web/followMac/getFollowMacList', {}).then().catch()

 

不過需要在配置axios的config的baseURL,配置在config的baseURL會在url參數不為http開頭時添加在url前面

baseURL: '/agent',//本地測試
baseURL:'正式服務器路徑'

 

這樣就可以愉快的本地調試了,是利用node服務進行代理

 


免責聲明!

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



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