use-axios-well
use-axios-well copied to clipboard
点击之后在请求呢
`MessageBox({ title: '提示', message: '网络异常,请稍后再试', confirmButtonText: '刷新', showCancelButton: true, cancelButtonText: '返回', closeOnClickModal: false, }).then(action => { console.log(action); if (action === 'cancel') { // 返回上一页 router.go(-1); } else if (action === 'confirm') { // 确定刷新
var backoff = new Promise(function (resolve) {
resolve();
});
// Return the promise in which recalls axios to retry the request
return backoff.then(function () {
return axios(config);
});
}
})`
这里面的东西,我是写在拦截器里面的,所以页面在点击刷新按钮,数据要怎么获取呢 ??
axios.interceptors.response.use(function(response){
.....
MessageBox({
title: '提示',
message: '网络异常,请稍后再试',
confirmButtonText: '刷新',
showCancelButton: true,
cancelButtonText: '返回',
closeOnClickModal: false,
}).then(action => {
console.log(action);
if (action === 'cancel') { // 返回上一页
router.go(-1);
} else if (action === 'confirm') { // 确定刷新
///原来代码 start
// Increase the retry count
config.__retryCount += 1;
// Create new promise to handle exponential backoff
var backoff = new Promise(function(resolve) {
setTimeout(function() {
resolve();
}, config.retryDelay || 1);
});
return backoff.then(function() {
return axios(config);
});
///原来代码 end
}
});
....
@gethin94 你试下这样行不行~~
@gethin94 https://github.com/ssttm169/use-axios-well/blob/gethin94/src/main.js 你看看是否你想要的那种!~?
好像不行,因为再次请求后,没有去接收数据呀,拿不到。
你的代码试过了吗?
你看看这里的代码,我做了一个分支给你,这里是可以获取的,,那个 res https://github.com/ssttm169/use-axios-well/blob/e8f7310aa5f8090a9baeed23cbbd30b56e508f7f/src/pages/index.vue#L12-L19
@gethin94 如果还行,你给我远程协助,我帮你看看代码。~~加我企鹅:14665350
请问大佬解决了吗
@dengxiaozhen 解决了呀。