vue proxy 跨域代理

1.config/index.js 修改 proxyTablecss

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

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

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)
    })
  }
}