12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- //取值
- function get(key, sync=true) {
- try {
- if (sync) {
- return uni.getStorageSync(key);
- } else {
- let data = '';
- uni.getStorage({
- key: key,
- success: function(res) {
- data = res.data;
- }
- });
- return data;
- }
- } catch (e) {
- return false;
- }
- }
- //存值
- function set(key, value, sync=true) {
- try {
- if (sync) {
- return uni.setStorageSync(key, value);
- } else {
- uni.setStorage({
- key: key,
- data: value
- });
- }
- } catch (e) {
- }
- }
- //删值
- function del(key, sync=true) {
- try {
- if (sync) {
- return uni.removeStorageSync(key);
- } else {
- uni.removeStorage({
- key: key
- });
- }
- } catch (e) {
- return false;
- }
- }
- //清除本地缓存
- function clear(sync=true) {
- try {
- if (sync) {
- return uni.clearStorageSync();
- } else {
- uni.clearStorage();
- }
- } catch (e) {
- return false;
- }
- }
- export {
- get,
- set,
- del,
- clear
- }
|