vue-hooks取消上一次请求

// 根路由相关的hook 钩子 全局钩子
import store from '@/vuex/store';
import * as types from '@/vuex/actions-type'

export default {
  // 标识 当前的hook的作用
  cancelToken: (to, from, next) => {
    console.log("进行")
    // 清除token
    store.commit(types.CLEAR_TOKEN); // 清除所有的请求
    next(); // 继续王下走
  },

  // 给每一个hook 对应一个功能
  permission: (to, from, next) => {
    next(); // 继续王下走
  }
}


[types.PUSH_TOKEN](state, cancel) {
      console.log("state",state.ajaxToken)
      // 也可以使用push
      state.ajaxToken = [...state.ajaxToken, cancel]
    },
    [types.CLEAR_TOKEN](state) {
      // 依次调用取消请求的方法
      state.ajaxToken.forEach(cancel => cancel());
      state.ajaxToken = []; // 清空数组
    },
发布了80 篇原创文章 · 获赞 5 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_28473733/article/details/103250529