vue3:pinia仓库store解构(vue3 $store)
原文:「链接」
wx提问:
vue3:pinia仓库store解构
引入的 import { useTestStore } from "../../store"; 文件请查看
vue3:pinia 基础使用方法:「链接」
1. 解构 store 数据
import { useTestStore } from "../../store";
let test = useTestStore();
//解构: pinia 解构不具有响应式
const { current, name } = test;
1.1 解构后的数据会失去响应式
2. 解构后的数据保持响应式利用 storeToRefs
import { useTestStore } from "../../store";
import { storeToRefs } from "pinia";
let test = useTestStore();
// storeToRefs 解构后可以依旧保持响应式
const { current, name } = storeToRefs(test);
原文:「链接」
wx提问: