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);//需要這樣獲取到數組
});
學習筆記,如有不足請多多指教!