vue proxy 跨域代理

1.config/index.js 修改 proxyTable proxyTable: { '/api': { target: 'http://shuige.wicp.vip/', //目标接口域名 changeOrigin: true, //是否跨域...

1.config/index.js 修改 proxyTable

    proxyTable: {
      '/api': {
        target: 'http://shuige.wicp.vip/',  //目标接口域名
        changeOrigin: true,  //是否跨域
        pathRewrite: {
          '^/api': '/'   //重写接口 后台接口指向不统一  所以指向所有/
        }
      },
      cssSourceMap: false
    },

2. 请求得时候 接口地址加上前缀

import axios from 'axios'
export default {
  created() {
    // 1. 代理成功
    // http://shuige.wicp.vip/users/proxy  转换成 http://localhost:8080/api/users/proxy 
    axios.get('/api/users/proxy').then(res => { // /api 不能少
      console.log(res)
    })
  }
}
  • 发表于 2020-04-09 10:27
  • 阅读 ( 180 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除