为了账号安全,请及时绑定邮箱和手机立即绑定

vue为啥会访问两次后端接口呢

vue为啥会访问两次后端接口呢

大话西游666 2018-07-09 12:12:42
查看完整描述

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方法有两个参数,第一个参数是响应成功时的回调函数,第二个参数是响应失败时的回调函数。

查看完整回答
反对 回复 2018-08-26
  • 1 回答
  • 0 关注
  • 5258 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信