swan.removeStorage
解释:从本地缓存中异步移除指定 key。
方法参数
Object object
object参数说明
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
key | String | 是 | 本地缓存中的指定的 key | |
success | Function | 否 | 接口调用成功的回调函数 | |
fail | Function | 否 | 接口调用失败的回调函数 | |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例
请使用百度APP扫码
图片示例
代码示例1 - 基础用法
- 在 js 文件中
swan.removeStorage({
key: 'xxx',
success: res => {
console.log('removeStorage success', res);
},
fail: err => {
console.log('removeStorage fail', err);
}
});
代码示例2 - 业务场景 - 搜索历史
- 在 js 文件中
storageQuery(value) {
let queryArr = this.getData('queryArr');
if (value) {
const index = queryArr.findIndex(item => item === value);
if (index > -1) {
queryArr.splice(index, 1);
}
queryArr.unshift(value);
}
const storeArr = queryArr.slice(0, 20);
swan.setStorageSync('queryData', storeArr);
},
clearQuery() {
swan.removeStorageSync('queryData');
this.setData('queryArr', []);
console.log('搜索历史清空成功');
}
错误码
Android
错误码 | 说明 |
---|---|
201 | 解析失败,请检查调起协议是否合法 |
1001 | 执行失败 |
iOS
错误码 | 说明 |
---|---|
202 | 解析失败,请检查参数是否正确 |