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)
    })
  }
}
相關文章
相關標籤/搜索