清空 (@momo4) 在 vue3里面的pinia里面的storeToRefs 中发帖
Pinia 提供的 storeToRefs 只会将 Pinia store 中的 状态(state) 属性转化为 ref 对象,而 Vue 的 toRefs 会将整个 store 中的所有数据(包括state、getters 和 actions)都转换为 ref,因此它们的行为有细微的区别。
理解 storeToRefs 和 toRefs
1. storeToRefs (Pinia 提供的)
作用:只将 Pinia Store 中的 state(即状态数据)转为 Vue 的 ref。
特点:它只针对 state 进行操作,忽略 actions 和 getters。
2. toRefs (Vue 提供的)
作用:将一个响应式对象(通常是 reactive 的对象)中的所有属性转换为 ref。
特点:它会尝试将 store 中所有的数据(包括 state、getters、甚至 acti...