Vue solve cross-domain

vue-cli project, solve cross-domain problems.

proxyTable inside the config> index.js add configuration file

proxyTable: {
      '/api': {  //使用"/api"来代替"http://f.apiplus.c"
        target: 'http://f.apiplus.cn', //源地址
        changeOrigin: true, //改变源
        pathRewrite: {
          '^/api': 'http://f.apiplus.cn' //路径重写
      }
   }
},

Component in vue

this.axios({
     url: '/api/mall/servlet/json?funcNo=3040',
     // url: 'http://f.apiplus.cn/mall/servlet/json?funcNo=3040',
     method: 'get',
}).then(res => {
   console.log(res)
}).catch(error => {
   console.log(error)
})

Need to re-run the project, or will be error

Local development will not re-run the project after a cross-domain issues

Guess you like

Origin www.cnblogs.com/jiaxinzhu/p/12024479.html
Recommended