JS监听VUE的HASH变化

2019-03-05 / 1 评论 / 225 阅读 / 正在检测是否收录...
(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

    根本无效

    回复