import {defineStore} from pinia
export const userInfoStore = defineStore('userInfo',{
state: ()=>({count:0, name: 'Eduardo'})
getters:{
doubleCount:(state) => state.count * 2
}
actions:{
increment(){
this.count++
}
}
})
export const useInfoStore = defineStore('userInfo', ()=>{
const count = ref(0)
const name = ref('eduardo')
const doubleCount = computed(()=>count.value*2)
function increment(){
count.value++
}
return {count, name, doubleCount, increment}
})
必须return state的所有属性。
使用
import { userInfoStore } from '@/stores/counter'
const userinfoStore = userInfoStore()