创建store文件夹,定义了一个 Pinia store,用于在 Vue 应用中管理共享状态

pull/4/head
riverflow 2 months ago
parent 43cd63ad76
commit ea6b7fbb6f

@ -0,0 +1,31 @@
import { defineStore } from 'pinia'
// `defineStore()` 的返回值的命名是自由的
// 但最好含有 store 的名字,且以 `use` 开头,以 `Store` 结尾。
// (比如 `useUserStore``useCartStore``useProductStore`)
// 第一个参数是你的应用中 Store 的唯一 ID。
export const testStore = defineStore('testStore', {
// state可以理解为一个共享的内存
state: () => {
return {
count: 0
}
},
// getter
getters:{
// 数据放在state里面需要传递state
doubleCount(state){
return state.count
}
},
// action
actions:{
// 设置state里面的数据
// count:number表示传递进去的count应该是一个number类型
setCount(count:number){
this.count = count
}
}
})
Loading…
Cancel
Save