flat: 缓存
This commit is contained in:
35
uni_modules/pinia-plugin-unistorage/src/index.ts
Normal file
35
uni_modules/pinia-plugin-unistorage/src/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
createPersistedState,
|
||||
type PersistedStateFactoryOptions,
|
||||
} from "pinia-plugin-persistedstate";
|
||||
|
||||
export * from "pinia-plugin-persistedstate";
|
||||
|
||||
export function createUnistorage(
|
||||
globalOptions: PersistedStateFactoryOptions = {},
|
||||
) {
|
||||
const persistedState = createPersistedState({
|
||||
storage: {
|
||||
getItem(key) {
|
||||
// @ts-ignore
|
||||
return uni.getStorageSync(key);
|
||||
},
|
||||
setItem(key, value) {
|
||||
// @ts-ignore
|
||||
uni.setStorageSync(key, value);
|
||||
},
|
||||
},
|
||||
serializer: {
|
||||
deserialize: JSON.parse,
|
||||
serialize: JSON.stringify,
|
||||
},
|
||||
...globalOptions,
|
||||
});
|
||||
// @ts-ignore
|
||||
return (ctx) => {
|
||||
if (ctx.options.unistorage) {
|
||||
ctx.options.persist = ctx.options.unistorage;
|
||||
}
|
||||
return persistedState(ctx);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user