@sheto/storage
Version:
你见过这么方便的Storage操作库吗?我见过,就是这个!
35 lines (34 loc) • 810 B
JavaScript
import { _batchInitStore } from './utils';
import { BasicStore } from "./index";
/**
* @description Uniapp Storage的适配器
*/
class UniappStorageAdapter {
get length() {
const { currentSize } = uni.getStorageInfoSync();
return currentSize;
}
;
clear() {
uni.clearStorageSync();
}
removeItem(_Key) {
uni.removeStorageSync(_Key);
}
setItem(_Key, _Value) {
uni.setStorageSync(_Key, _Value);
}
getItem(_Key) {
return uni.getStorageSync(_Key);
}
key(_Index) {
const { keys } = uni.getStorageInfoSync();
return keys[_Index];
}
}
export class StoragePlus extends BasicStore {
constructor(_Name) {
super(new UniappStorageAdapter());
_batchInitStore.call(this, _Name);
}
}