1.0.1 • Published 10 months ago

fine-ajax-hook v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Fine Ajax Hook

介绍

背景:https://work.fineres.com/browse/REPORT-74928?filter=30408

原理:基于ajax-hook做了一层封装。

API

用法和 ajax-hook 没太大差别:

// 挂载代理
window._FINE_AJAX_HOOK
    .proxy({
        // 代理请求
        onRequest: (config, handler) => {
            // 改变config
            config.xxx = xxx;

            // 传递config
            return handler.next(config);
        },
        // 代理响应
        onResponse: (response, handler) => {
            // 改变response
            response.xxx = xxx;

            // 传递response
            return handler.next(response);
        },
    })
    // 支持链式调用
    .proxy({ proxyObj })
    .proxy({ proxyObj });

// 卸载代理
window._FINE_AJAX_HOOK.unProxy();

handler.next用于传递信息,handler.resolvehandler.reject含义则与 ajax-hook 一致。

当前暂不支持hook(...)方法。

1.0.1

10 months ago

1.0.0

10 months ago