axios终止网络请求

4,148 阅读1分钟

axios中止单个网络请求

    const CancelToken = axios.CancelToken
    config.cancelToken = new CancelToken((cancel) => {
        // 存储并使用cancel
    })

axios中止所有的网络请求

  • 使用CancelToken
  • 在axios的请求拦截中,使用store存储每个请求的cancelToken实例
  • 拦截路由,调用cancelToken()方法终止请求

几种控制页面隐藏与显示的方式

opacity

  1. 控制透明度
  2. 父级及子级事件生效
  3. 子级根据最小的opacity生效

v-show

  1. 本质使用display: none|block
  2. 不占位,元素节点存在
  3. 父级优先级

v-if

  1. 不占位
  2. 元素从页面中去除

监听路由

使用watch

    watch: {
        $route(to,from) {
            //
        }
    }
    watch: {
        '$route': 'method'
    }
    watch: {
        $route: {
            handler: function(to,from) {
                //
            },
            deep: true
        }
    }

vue-router的声明周期钩子

    beforeRouteEnter(to,from,next) {
        //
    }
    beforeRouteUpdate(to,from,next) {
        //
    }
    beforeRouteLeave(to,from,next) {
        //
    }

全局路由拦截

    router.beforeEach((to,from,next) => {
        //
    })
    router.beforeResolve((to,from,next) => {
        //
    })
    router.afterEach((to,from) => {
        //
    })

路由独享守卫

    {
        path: xxx,
        name: xxx,
        component: xxx,
        beforeEnter: (to,from,next) => {
            //
        }
    }