webpack之proxyTable配置

有两种情况:

一,有统一的项目名

config下index.js

配置如下:

    proxyTable: {
      '/tbt_user':{
        target: 'http://47.98.216.251:80', //测试线
        changeOrigin: true, // 是否跨域
        pathRewrite: {
          '^/tbt_user': '/tbt_user'
        }
      }

页面接口调用

    this.$axios.post('/tbt_user/third/pay/query').then((response) => {
      console.log(response)
    }).catch(err => {
      console.log('err')
      console.log(err)
    })

二,没有统一项目名

    proxyTable: {
      '/api':{
        target: 'http://47.94.142.215:8082', // 测试
        changeOrigin: true, // 改变源(是否跨域)
        pathRewrite: {
          '^/api': '/'
        }
      }
    }

页面调用:

    this.$axios.post('/api/third/pay/query').then((response) => {
      console.log(response)
    }).catch(err => {
      console.log('err')
      console.log(err)
    })

猜你喜欢

转载自www.cnblogs.com/wang715100018066/p/10616984.html