use-axios-well icon indicating copy to clipboard operation
use-axios-well copied to clipboard

点击之后在请求呢

Open gongxi036 opened this issue 6 years ago • 9 comments

`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);
    });
  }
})`

gongxi036 avatar Jun 04 '18 10:06 gongxi036

这里面的东西,我是写在拦截器里面的,所以页面在点击刷新按钮,数据要怎么获取呢 ??

gongxi036 avatar Jun 04 '18 10:06 gongxi036

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

	}
});
....

ssttm169 avatar Jun 04 '18 11:06 ssttm169

@gethin94 你试下这样行不行~~

ssttm169 avatar Jun 04 '18 11:06 ssttm169

@gethin94 https://github.com/ssttm169/use-axios-well/blob/gethin94/src/main.js 你看看是否你想要的那种!~?

ssttm169 avatar Jun 04 '18 11:06 ssttm169

post

好像不行,因为再次请求后,没有去接收数据呀,拿不到。

你的代码试过了吗?

gongxi036 avatar Jun 05 '18 02:06 gongxi036

你看看这里的代码,我做了一个分支给你,这里是可以获取的,,那个 res https://github.com/ssttm169/use-axios-well/blob/e8f7310aa5f8090a9baeed23cbbd30b56e508f7f/src/pages/index.vue#L12-L19

ssttm169 avatar Jun 05 '18 03:06 ssttm169

@gethin94 如果还行,你给我远程协助,我帮你看看代码。~~加我企鹅:14665350

ssttm169 avatar Jun 05 '18 03:06 ssttm169

请问大佬解决了吗

cat-kun avatar Sep 10 '18 01:09 cat-kun

@dengxiaozhen 解决了呀。

ssttm169 avatar Sep 10 '18 02:09 ssttm169