报错信息
Uncaught SyntaxError: "undefined" is not valid JSON
at JSON.parse (<anonymous>)
at state (permiss.ts:11:21)
at setup (pinia.esm-browser.js:1174:49)
at pinia.esm-browser.js:1414:32
at EffectScope.run (reactivity.esm-bundler.js:33:24)
at pinia.esm-browser.js:1414:22
at EffectScope.run (reactivity.esm-bundler.js:33:24)
at createSetupStore (pinia.esm-browser.js:1412:33)
at createOptionsStore (pinia.esm-browser.js:1202:13)
at useStore (pinia.esm-browser.js:1686:17)
相关代码
export const usePermissStore = defineStore('permiss', {
state: () => {
const keys = localStorage.getItem('ms_keys');
return {
key: keys ? JSON.parse(keys) : <string[]>[],
defaultList: <ObjectList>{
admin: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16'],
user: ['1', '2', '3', '11', '13', '14', '15']
}
};
},
actions: {
handleSet(val: string[]) {
this.key = val;
}
}
});