1 :找到config目录下的 index.js文件

Vue 中 axios 跨域请求

2  找到 dev里 的 proxyTable 属性  并修改

Vue 中 axios 跨域请求

proxyTable: {
  "/api":{
    target: 'http://localhost:8080',//http://localhost:8080是我的javaweb务器(我的vue服务http://localhost:8081)
    changeOrigin: true,
    pathRewrite: {
      '^/api': '/'
    }
  }
}

3 修改完成 开始跨域访问访问

(/api)必须添加 才可以访问

this.axios.get('/api/test').then(function (d) { console.log(d.data) })

 

相关文章: