微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

uniapp 缓存多个数据

获取

			uni.getStorage({
				key:'username',
			}).then(res => {
				// 如果返回数组为两位就是正确
				if(res.length==2){
					this.username = res[1].data;
				}
				return uni.getStorage({
					key:'password',
				})
			}).then(res => {
				if(res.length==2){
					this.password = res[1].data;
				}
				return uni.getStorage({
					key:'ipAddress',
				})
			}).then(res => {
				if(res.length==2){
					this.ipAddress = res[1].data;
				}
			})

  添加

							uni.setStorage({
								key:'token',
								data: res.access_token,
							}).then(res => {
								// console.log("保存token");
								return uni.setStorage({
									key:'username',
									data: this.username,
								})
							}).then(res => {
								// console.log("保存name");
								return uni.setStorage({
									key:'password',
									data: this.password,
								})
							}).then(res => {
								// console.log("保存password");
								return uni.setStorage({
									key:'ipAddress',
									data: this.ipAddress,
								})
							}).then(res => {
								// console.log("保存ipAddress");
								uni.switchTab({
									url: './home'
								})
							})

  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐