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