import{ userNumStore }from"../store/count";import{ storeToRefs }from"pinia";const userNum =userNumStore();//结构出来的具有响应式// let { num, stu, stuInfo, sumNum } = storeToRefs(userNum);let{ num, stu }=storeToRefs(userNum);
以上是选项式写法
5.下面组合式使用
import{ ref }from'vue'exportconst userNumStore =defineStore('numStore',()=>{let num =ref(100)let stu =ref({name:'王祥林',age:20})constadd=(val: number)=>{
num.value += val + num.value
}return{ add, num, stu }})