安装

1
2
npm install pinia
npm i pinia-plugin-persist

store

在src下面新建store文件夹,在此文件夹下新建index.js

image-20220526103538454

main.js

在main.js中将store引进来,并挂载在app上

1
2
3
4
5
6
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
createApp(App).use(store).use(router).mount('#app')

index.js

引入pinia

1
2
3
4
5
6
import { createPinia } from "pinia";
import piniaPluginPersist from 'pinia-plugin-persist'
const store = createPinia()
store.use(piniaPluginPersist)

export default store

分模块

在store下面新建模块的js