监听localstorage变化
export default function tools() {
const signSetItem = localStorage.setItem;
localStorage.setItem = function (key, val) {
const setEvent = new Event('setItemEvent');
setEvent.key = key;
setEvent.value = val;
window.dispatchEvent(setEvent);
signSetItem.apply(this, arguments);
};
}
在main.js中引入使用
import storage from './utils/locaStorage';
Vue.use(storage);
监听
window.addEventListener('setItemEvent', (event: any) => {})