vue跨域配置


根目錄新建  vue.config.js文件:

添加如下代碼:

 1 module.exports = {
 2   outputDir: 'dist', //build輸出目錄
 3   assetsDir: 'assets', //靜態資源目錄(js, css, img)
 4   lintOnSave: false, //是否開啟eslint
 5   devServer: {
 6     open: true, //是否自動彈出瀏覽器頁面
 7     host: "localhost",
 8     port: '8081',
 9     https: false,
10     hotOnly: false,
11     proxy: {
12       '/api': {14         target: 'http://erp.f-ev.com/PBaoXFIsvT.php/facrm/analysis', //自己的服務器的地址
15         changeOrigin: true,
16         pathRewrite: {
17           '^/api': ''
18 
19         }
20       }
21     }
22   }
23 }

然后請求寫法 URL前綴加上api即可:

this.$axios({
          method: 'post',
          url: '/api/Kpi/selectpage_yunying',
        }).then((res) => {
          if (res.data.code == "200") {
            
          }
        });

到此結束!


免責聲明!

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



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