安装
npm install pinia
npm install pinia-plugin-persistedstate
1.创建store文件夹,创建index.js文件
import {
createPinia} from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'//数据持久化
const pinia = createPinia()
export pinia
2.在main文件中引入pinia并创建容器挂载到根实例上
import App from './App.vue';
import {
createApp } from 'vue';
import {
pinia} from '@/store/index.js';
const app = createApp(App);
app.use(pinia);</