function dispatchEventStroage () { const signSetItem = localStorage.setItem; localStorage.setItem = function (key, val) { let setEvent = new Event('setItemEvent') setEvent.key = key setEvent.newValue = val window.dispatchEvent(setEvent) signSetItem.apply(this, arguments) } }; dispatchEventStroage(); window.addEventListener('setItemEvent', function (e) { console.log('change信息:',e); })
标签:function,val,setEvent,localStorage,key,signSetItem,监听 From: https://www.cnblogs.com/swt-axios/p/16721970.html