插件http-proxy-middleware在vue-cli中的使用


作用:把后端的API(遠程的API) 請求代理到本地服務器上,方便與后台數據調試,前后端分離

server.js 模擬遠程API :localhost:8060/api/search  (測試前運行 node server.js)

  

在vue-cli中的使用:運行localhost: 8080

1.在config文件夾下創建proxyConfig.js如下

                     

2. 在/config/index.js中 引入,並配置

      const  proxyConfig = require('./proxyConfig')

          

          

 

前端http請求遠程API:在create鈎子時調用 this.test() 請求到API結果:我是遠程的數據源

      

 學習資料詳細:

      1.https://github.com/chimurai/http-proxy-middleware

      2.https://vuejs-templates.github.io/webpack/proxy.htm

  


免責聲明!

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



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