the first method, directly assigning value(not recommended):
useStore().stateItem = newVal.the second, using
$patchmethod. The parameter types of$pathmethod has two ways:useStore().$patch(stateObject), which requires passsing an entire state object; The second type:useStore().$patch((state) =>{state.item = newVal}).the third, calls to pinia's actions:
const useStore = defineStore('users', {
state: ()=> ({
count: 0
}),
actions: {
increment: (newVal) => {
this.count = newVal
}
}
})
Top comments (0)