JS监听VUE的HASH变化

2019-03-05 / 1 评论 / 585 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年01月28日,已超过979天没有更新,若内容或图片失效,请留言反馈。
(history) {
    let pushState = history.pushState;
    history.pushState = function(state) {
        if (typeof history.onpushstate === 'function') {
            history.onpushstate({ state: state });
        }
        return pushState.apply(history, arguments);
    };
    let replaceState = history.replaceState;
    history.replaceState = function(state) {
        if (typeof history.onreplacestate === 'function') {
            history.onreplacestate({ state: state });
        }
        return replaceState.apply(history, arguments);
    };
})(window.history);
window.onhashchange = window.onpopstate = history.onpushstate = history.onreplacestate = function() { console.log('change!')};
0

评论 (1)

取消
  1. 头像
    艾尔 作者
    MacOS · Google Chrome

    根本无效

    回复