uni-app的数据缓存

数据缓存uni.setStorage

将数据存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个异步接口。

参数名 类型 必填 说明
key String 本地缓存中的指定的 key
data Any 需要存储的内容,只支持原生类型、及能够通过 JSON.stringify 序列化的对象
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)
		<view>
			<button @click="setStorage">存储数据</button>
		</view>
setStorage(){
   
	uni.setStorageSync("storageKey","hello");
	console.log("-------------",uni.getStorageSync("storageKey"));
	uni.removeStorageSync("storageKey")
	uni.clearStorageSync()
}

在这里插入图片描述

存储数据

setStorage(){
   
	uni.setStorage({
   
		key:'storageKey',
		data:'hello',
		success:function(){
   
			console.log("存储成功");
		}
	});
}

在这里插入图片描述

读取数据

setStorage(){
   
	uni.getStorage({
   
		key:'storageKey',
		data: 'hello',
		success:function(res){
   
			console.log("读取成功",res.data);
		}
	});
}

在这里插入图片描述

删除数据

setStorage(){
   
	uni.removeStorage({
   
		key:'storageKey',
		success:function(){
   
			console.log("删除成功");
		}
	});
}

在这里插入图片描述

获取数据信息

setStorage(){
   
	uni.getStorageInfo({
   
		success:function(res){
   
			//获取当前storage中的所有key
			console.log(res.keys)
			//获取当前占用空间的大小 KB 单位
			console.log(res.currentSize);
			//限制的空间大小 KB
			console.log(res.limitSize);
		}
	})
}

在这里插入图片描述

相关推荐

  1. uni-app优缺点?

    2024-01-18 14:20:02       49 阅读
  2. uni-app页面数据传参方式

    2024-01-18 14:20:02       66 阅读
  3. uni.app】动态赋值字典类数据问题及解决方案

    2024-01-18 14:20:02       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-18 14:20:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-18 14:20:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-18 14:20:02       87 阅读
  4. Python语言-面向对象

    2024-01-18 14:20:02       96 阅读

热门阅读

  1. 历史日志·洪武朝武功一览

    2024-01-18 14:20:02       45 阅读
  2. Mysql需要了解的常用命令

    2024-01-18 14:20:02       47 阅读
  3. 题目 1761: 学习ASCII码

    2024-01-18 14:20:02       57 阅读
  4. Centos下,使用NFS实现目录共享/网络驱动器

    2024-01-18 14:20:02       48 阅读