swan.removeStorage
解释:从本地缓存中异步移除指定 key。
方法参数
Object object
object参数说明
示例
请使用百度APP扫码
图片示例
代码示例1 - 基础用法
在开发者工具中预览效果 -
swan.removeStorage({ key: 'xxx', success: res => { console.log('removeStorage success', res); }, fail: err => { console.log('removeStorage fail', err); } });
代码示例2 - 业务场景 - 搜索历史
在开发者工具中预览效果 -
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('搜索历史清空成功');}
