学习Pinia 第六章(API)
1.$reset重置store到他的初始状态state: () => ({user: <Result>{},name: "default",current:1}),Vue 例如我把值改变到了10const change = () => {Test.current++}调用$reset();将会把state所有值重置回 原始状态...
·
1.$reset
重置store
到他的初始状态
state: () => ({
user: <Result>{},
name: "default",
current:1
}),
Vue 例如我把值改变到了10
const change = () => {
Test.current++
}
调用$reset();
将会把state所有值 重置回 原始状态
2.订阅state的改变
类似于Vuex 的abscribe 只要有state 的变化就会走这个函数
Test.$subscribe((args,state)=>{
console.log(args,state);
})
返回值
第二个参数
如果你的组件卸载之后还想继续调用请设置第二个参数
Test.$subscribe((args,state)=>{
console.log(args,state);
},{
detached:true
})
3.订阅Actions的调用
只要有actions被调用就会走这个函数
Test.$onAction((args)=>{
console.log(args);
})
更多推荐
已为社区贡献31条内容
所有评论(0)