vue2 與后台信息交互


vue-resource  是vue的ajax請求插件

vue-resource文檔:https://github.com/vuejs/vue-resource/blob/master/docs/http.md

vue-resouce 已經解決了vue跨域問題

栗子:

 

this.$http.post(“http://192.168.1.25:20070/api/TypeItems/VehicleBrand”,{pagenum:0,pagesize:15,VehicleType:1}).then((response) => {

response = response.body;
 console.log(response.data);//需要這樣獲取到數組
});

 

url集中整理獲取

新建一個配置文件 config.js 而后在文件中整理url

var ipUrl = 'http://192.168.1.25:20070';
var API = {
VehicleBrand: ipUrl+"/api/TypeItems/VehicleBrand"
}

module .exports = API; //創建模塊api

而后在需要的頁面引入config.js
import API from  'common/config'

就可以這樣獲取獲取url使用了
this.$http.post(API.VehicleBrand,{pagenum:0,pagesize:15,VehicleType:1}).then((response) => {
response = response.body;
console.log(response.data);//需要這樣獲取到數組
});

學習筆記,如有不足請多多指教!


免責聲明!

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



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