1 回答

慕尼黑5688855
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获取后台数据,成功后执行then的代码
Vue.http.get('/someUrl', [options]).then(successCallback, errorCallback);
3、在一个Vue实例内使用$http
// $http是在vue的局部范围内的实例
this.$http.get('/someUrl', [options]).then(successCallback, errorCallback);
说明:
在发送请求后,使用then方法来处理响应结果,then方法有两个参数,第一个参数是响应成功时的回调函数,第二个参数是响应失败时的回调函数。
添加回答
举报
0/150
提交
取消