vue-cli與后台數據交互增刪改查


1. 安裝vue-resource 

npm install vue-resource --save

2.訪問后台地址,在vue中會出現跨域的問題,以下為解決方案

  在config下的index.js 中配置proxyTable代理設置

proxyTable: {
        '/api':{
            target:'http://19******:8080',
            changeOrigin:true,//允許跨域
            pathRewrite:{
                '/api':'/'
            }
        }
    },

3.地址配置完了,就可以開始訪問后台,獲取數據了
 我用的是vue-resource,有多種方式 get,post,json,jsonp,具體使用方法,可以查看官網

this.$http.get('url').then(response => { 
        console.log(response.body); 
      }, response => { 
        console.log(response); 
  });
this.$http.post(('url'),data ,{emulateJSON:false}).then(response => { 
       console.log(response.body);
      }, response => {
       console.log(response);
  });

 

 


免責聲明!

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



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