美文网首页
在拦截器中对特殊接口进行loading延时的处理

在拦截器中对特殊接口进行loading延时的处理

作者: 琳媚儿 | 来源:发表于2020-12-21 15:30 被阅读0次

    if (response.data.protocol === '102002') {
    setTimeout(() => {
    load.tryHideFullScreenLoading()
    }, 6000)
    }

    // 添加respone拦截器
    service.interceptors.response.use(
      response => {
        const res = {} // eslint-disable-line no-unused-vars
        if (response.data.protocol === '102002') {
          setTimeout(() => {
            load.tryHideFullScreenLoading()
          }, 6000)
        } else {
          load.tryHideFullScreenLoading()
          if (!response.data.sucess && response.config.responseType !== 'arraybuffer') { // eslint-disable-line no-unused-vars
            if (isErrorResponse(response.data.paramBody)) {
              console.log(response.data)
              store.dispatch('user/logout')
              router.replace('/login')
              return response.data
            }
          }
        }
        console.log(response)
    
        if (response.status === 200) {
          return response.data
        } else {
          console.log('出错')
          return response.data
        }
      },
      error => {
        load.tryHideFullScreenLoading()
        if (error.response && error.response.status === 404) {
          console.log('eeeeeee')
        }
        return Promise.reject(error.response)
      }
    )
    

    相关文章

      网友评论

          本文标题:在拦截器中对特殊接口进行loading延时的处理

          本文链接:https://www.haomeiwen.com/subject/clxrnktx.html