let genStorageSyncCode = () => {
const kvList = []
for (let i = 0; i < localStorage.length; i++) {
const k = localStorage.key(i)
const v = localStorage.getItem(k)
kvList.push({
k, v
})
}
const code = `${kvList.map((item) => {
return `localStorage.setItem('${item.k}','${item.v}')`
}).join(';')}`
return code
}
console.log(genStorageSyncCode())
直接导出代码,复制到另外一个页面控制台console粘贴回车即可进行storage同步
荣耀属于 yinode
https://yinode.tech/post/202110/js-localstorage-%E5%AF%BC%E5%87%BA%E5%AF%BC%E5%85%A5%E5%B7%A5%E5%85%B7/