我的项目中引入的是vue2.min.js 、 vue-resource.min.js 文件,这个我要如何设置回调函数呢? this.$http.post(url, { keywords : [
{ 'key' : key, 'limit' : 50 }
]
},{timeout : 3000}).then(function(res) { console.log(res)
},function(err){ console.log(err)
})
1 回答
BIG阳
TA贡献1859条经验 获得超6个赞
找到解决方案了,给遇到同样问题的小伙伴一个参考!
使用拦截器
Vue.http.interceptors.push(function(request, next) { var timeout if (request.timeout) {
clearTimeout(timeout)
timeout = setTimeout(function() { console.log('请求超时啦。。。。')
request.abort()
}.bind(this), request.timeout)
}
next(function(response) { return response
})
})添加回答
举报
0/150
提交
取消
