账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    为什么axios.interceptors执行了两次。
    42
    0

    为什么axios.interceptors执行了两次

     
     new Vue({
        router,
        store,
        created() {
          Vue.prototype.$http = axios;
          this.$http.interceptors.response.use(response => {
            console.log('-----')
                    return response.data
                }, error => {
                    if (error && error.response && error.response.status == "401") {
              this.$cookies.remove("userName");
              this.$cookies.remove("token");
              //应该清除router路由信息,不然菜单会有问题
              this.$router.options.routes = [];
                        this.$router.push({ path: "/login" });
                    }
                    return Promise.reject(error)
          });
          if (VueCookies.get("token")) {
            axios.defaults.headers["Authorization"] = VueCookies.get("token");
            store.dispatch("UpdateMenu");
          } else {
            this.$cookies.remove("userName");
            this.$cookies.remove("token");
            //应该清除router路由信息,不然菜单会有问题
            this.$router.options.routes = [];
            this.$router.push({ path: "/login" });
          }
        },
        render: h => h(App)
      }).$mount('#app');

    打印了两行“----”。其他地方没有设置axios.interceptors

    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部