监听 HTTP Response Header 事件,提示方法不存在
119 浏览2025年10月28日作者:lnb_
const requestTask = tt.request({
        url: url,
        header: {
            'Authorization': tt.getStorageSync('Authorization'),
            'Info': tt.getStorageSync('headerInfo'),
            'accept': 'application/json'
        },
        method: method,
        data: data,
        success: function(res) {
            if (res.statusCode === 200) {
                if (res.data.code === 0) {
                    success(res.data.data);
                  } else {
                    error && error(res.data);
                  };
            }else{
                error && error(res.data);
            }
        },
        fail: function(e) {
            error && error(e);
        },
        complete: function() {
            if (desc) tt.hideLoading();
        }
    })
    console.log(requestTask, 'requestTask')
    requestTask.onHeadersReceived(function(res) { // request拦截器
        if ('Authorization' in res.header || 'authorization' in res.header) {
          const token_data = res.header.Authorization || res.header.authorization;
          tt.setStorageSync('Authorization', token_data);
        };
    });
最后一次编辑于 2025 年 10 月 28 日
共 3 条评论

相关问答

专题推荐

热门文章

热门问答