You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
495 B
JavaScript

import {
defineStore
} from 'pinia'
/**
* 测试持久化数据仓库
*/
export const useDemo2Store = defineStore('useDemo2Store', {
state: () => {
return {
name: undefined,
age: 18,
sex: true
}
},
//计算字段
getters: {
getName() {
return this.name || '匿名'
},
getSex() {
return this.sex ? '男' : '女';
}
},
//方法
actions: {
setName(name) {
this.name = name;
}
},
unistorage: true // 开启后对 state 的数据读写都将持久化
})