我的項(xiàng)目中引入的是vue2.min.js 、 vue-resource.min.js 文件,這個(gè)我要如何設(shè)置回調(diào)函數(shù)呢? this.$http.post(url, { keywords : [
{ 'key' : key, 'limit' : 50 }
]
},{timeout : 3000}).then(function(res) { console.log(res)
},function(err){ console.log(err)
})
1 回答

BIG陽(yáng)
TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
找到解決方案了,給遇到同樣問(wèn)題的小伙伴一個(gè)參考! 使用攔截器 Vue.http.interceptors.push(function(request, next) { var timeout if (request.timeout) { clearTimeout(timeout) timeout = setTimeout(function() { console.log('請(qǐng)求超時(shí)啦。。。。') request.abort() }.bind(this), request.timeout) } next(function(response) { return response }) })
添加回答
舉報(bào)
0/150
提交
取消