前后端分離_Vue_axios本地跨域(前端localhost:8080到后端localhost:8090)


  1. 找到vue.config.js
module.exports = {
  productionSourceMap: false,
  configureWebpack: {
    devServer: {
      proxy: {
        '/api': {
          target: 'http://localhost:8090', //設置調用的接口域名和端口號(默認端口號80)
          changeOrigin: true, //
          pathRewrite: {
            '^/api': ''
          }
               //這里理解成用‘/api’代替target里面的地址,
              //后面組件中我們掉接口時直接用api代替 
              //比如我要調用'http://40.00.100.100:3002/user/add',
              //直接寫‘/api/user/add’即可
        }
      }
    }
  },
  lintOnSave: false
}

  1. 調用實例
  this.$axios
                .get("api/assetPricing/findAll", {
                    params: {},
                })
                .then(res => {
                    // if (res.data.Code == 0) {
                    //     if (res.data.Status == null) {
                    //         this.items = []
                    //     } else {
                    //         this.items = res.data.Status
                    //     }
                    // }
                   window.console.log(res.data);
                })


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM