下载
npm i pinia-plugin-persistedstate
main.js中
import * as Pinia from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const pinia = Pinia.createPinia()
pinia.use(piniaPluginPersistedstate)
export function createApp() {
const app = createSSRApp(App)
app.use(pinia)
return {
app,
Pinia
}
}
stores/user.js中
import { defineStore } from 'pinia'
export const useStore = defineStore(
'main',
() => {
const someState = ref('hello pinia')
return { someState }
},
persist:{
//网页端开启
persist:true
storage: {
getItem: uni.getStorageSync,
setItem: uni.setStorageSync
}
},
)
相关作者
- 获取点赞0
- 文章阅读量3
评论()