Uniapp WeChat Mini Program Store/Get Local Cached Data @莫成尘

Look at the code first, you will see the following effect, just copy and use, the following code can be copied and pasted to use.

If you are satisfied, please give Mo Chengchen a Fabulous
If the interface data cannot be stored synchronously, try to use asynchronous
	    // 同步存储和读取
	    //设置 存储内容   参数为参数名,参数值 
		uni.setStorageSync('name',"莫成尘");
		//也可以这样写  uni.setStorageSync('name',this.name);
		//输出  仅仅使用参数名即可获取
		console.log(uni.getStorageSync('name'))
		//删除
		// uni.removeStorageSync('name')
//设置 异步存储内容   参数为参数名,参数值 
		uni.setStorage({
    
    
			key: "Name",
			data: '莫成尘'
		});
		//也可以这样写
		// uni.setStorage({
    
    
		//    key: "Name",
		//    data: this.name ? this.name : "君莫笑"
		// });
		//输出 
		uni.getStorage({
    
    
			key: 'Name',
			success(res) {
    
    
			console.log(res.data) //莫成尘
		}
		})
		//删除
		uni.removeStorage({
    
    
			  key: 'Name',
			 success (res) {
    
    
				 console.log(res) //removeStorage:ok
			}
		})
//清空 全部的本地缓存 这个方法会清除所有的记录 慎用
	uni.clearStorage()
		try {
    
    
		uni.clearStorageSync()
	} catch(e) {
    
    
		// Do something when catch error
	}

Additional and useful information that may appear has been annotated

If you have any questions about uniapp or you don’t understand this method, you can leave a message, I will reply as soon as possible and help you solve it.

Guess you like

Origin blog.csdn.net/weixin_47821281/article/details/109066646