Electron开发 electron-store报错

2,047 阅读1分钟

报错代码:

import GLOBAL from '~/const/globalVar'

import estore from "../../../estore/estore";

export default store => { store.subscribe((mutation, state) => { console.log(mutation, state) const type = mutation.type if (type.startsWith('TestItems')) { estore.set(GLOBAL.TEST_ITEM_KEY, state.items) } }) }

报错信息:

TypeError: Use delete() to clear values

报错原因:

        estore.set(GLOBAL.TEST_ITEM_KEY, state.items)
					
					设置的值为undefined时导致错误

解决办法:检查放入的值是否格式正确 正确代码:

 estore.set(GLOBAL.TEST_ITEM_KEY, state.TestItems.items)

知识补充:

.set(key, value) 设置一个项目。该值必须是JSON可序列化的。 尝试将类型设置为undefined,function或symbol会导致TypeError。

本文由博客群发一文多发等运营工具平台 OpenWrite 发布