1 回答

TA貢獻1848條經驗 獲得超2個贊
使用vue.js與后臺實現數據交互的方法是利用vue-resource組件提供的一系列api:
get(url, [data], [success], [options])
post(url, [data], [success], [options])
put(url, [data], [success], [options])
patch(url, [data], [success], [options])
delete(url, [data], [success], [options])
jsonp(url, [data], [success], [options])
具體舉例如下:
1、導入vue-resource
2、基于全局Vue對象使用http
// 通過someUrl獲取后臺數據,成功后執(zhí)行then的代碼
Vue.http.get('/someUrl', [options]).then(successCallback, errorCallback);
3、在一個Vue實例內使用$http
// $http是在vue的局部范圍內的實例
this.$http.get('/someUrl', [options]).then(successCallback, errorCallback);
說明:
在發(fā)送請求后,使用then方法來處理響應結果,then方法有兩個參數,第一個參數是響應成功時的回調函數,第二個參數是響應失敗時的回調函數。
添加回答
舉報