1.异步删除数据
使用wx.removeStorage(OBJECT)从本地缓存中异步删除指定KEY名称和对应的值,参数说明如下:
示例代码格式如下:
其中,引号内的key可替换成实际用到的KEY名称,且success()函数中res包含的内容为{errMsg:"removeStorage:ok"}
2.同步删除数据
使用wx.removeStorageSync(KEY)从本地缓存中同步删除指定KEY名称和对应的值,参数说明如下:
示例代码格式如下:
简单应用示例:
<!--wxml-->
<view class="title">数据存储的简单应用</view>
<view class="demo-box">
<view class="title">wx.removeStorage(OBJECT)异步删除</view>
<input name="key" placeholder="请输入KEY名称" bindinput="keyInput"></input>
<button type="primary" bindtap="removeStorage">数据异步删除</button>
</view>
<view class="demo-box">
<view class="title">wx.removeStorageSync(OBJECT)同步存储</view>
<input name="key1" placeholder="请输入KEY名称" bindinput="keyInput1"></input>
<button type="primary" bindtap="removeStorageSync">数据同步删除</button>
</view>
//js
Page({
keyInput:function(e){
this.setData({
key:e.detail.value
})
},
removeStorage:function(){
let key = this.data.key;
if(key.length==0){
wx.showToast({
title: 'KEY不能为空',
icon: 'none'
})
}else{
wx.removeStorage({
key: key,
success: function(res) {
wx.showToast({
title: '删除完毕!',
icon: 'none'
})
}
})
}
},
keyInput1: function (e) {
this.setData({
key1: e.detail.value
})
},
removeStorageSync:function(){
let key = this.data.key1;
if (key.length == 0) {
wx.showToast({
title: 'KEY不能为空',
icon: 'none'
})
} else {
wx.removeStorageSync(key);
wx.showToast({
title: '删除完毕!',
icon: 'none'
})
}
}
})