安装依赖
npm i pinia npm i pinia-plugin-persistedstate
新建 index.ts
import { createPinia } from 'pinia' import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化 const store = createPinia() store.use( createPersistedState({ storage: { getItem: uni.getStorageSync, setItem: uni.setStorageSync, }, }), ) export default store export * from './user'
新建 uesr.ts
import { defineStore } from "pinia"; import { reactive, ref } from "vue"; export const useUserStore = defineStore( "user", () => { const data = ref(999); const cktjia = () => { data.value++; };return { data, cktjia }; }, { persist: true, // 开启后对 state 的数据读写都将持久化 } );
min.ts 文件
import store from './store' app.use(store)
标签:uniapp,const,ts,更新,export,pinia,pinpa,import,store From: https://www.cnblogs.com/7788mmhh/p/18552366