欢迎光临
我们一直在努力

九八云百度小程序教程:swan.removeStorage

  • swan.removeStorage
    • 方法参数
      • object 参数说明
    • 示例
      • 图片示例
      • 代码示例 1:基础用法
      • 代码示例 2:搜索历史
    • 错误码
      • Android
      • iOS

    swan.removeStorage

    解释:从本地缓存中异步移除指定 key 。

    方法参数

    Object object

    object 参数说明

    属性名 类型 必填 默认值 说明

    key

    String

    本地缓存中的指定的 key

    success

    Function

    接口调用成功的回调函数

    fail

    Function

    接口调用失败的回调函数

    complete

    Function

    接口调用结束的回调函数(调用成功、失败都会执行)

    示例

    扫码体验

    代码示例

    请使用百度APP扫码

    图片示例

    代码示例 1:基础用法

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • SWAN
    • JS
    
     
    1. <view class="wrap">
    2. <view class="card-area">
    3. <view class="list-area border-bottom">
    4. <label class="list-item-key-4">key</label>
    5. <input class="list-item-value" bindfocus="keyFocus" bindinput="keyInput" type="text" value="{{key}}" placeholder="请输入key" />
    6. </view>
    7. <view class="list-area border-bottom">
    8. <label class="list-item-key-4">value</label>
    9. <input class="list-item-value" bindfocus="valueFocus" bindinput="valueInput" type="text" value="{{value}}" placeholder="请输入value" />
    10. </view>
    11. <view>
    12. <button bindtap="setStorage" type="primary" hover-stop-propagation="true">存储数据</button>
    13. <button bindtap="getStorage" type="primary" hover-stop-propagation="true" disabled="{{disabled}}">读取数据</button>
    14. <button bindtap="getStorageInfo" type="primary" disabled="{{disabled}}">获取存储数据信息</button>
    15. <button bindtap="removeStorage" type="primary" hover-stop-propagation="true" disabled="{{disabled}}">移除第一个key对应的value值</button>
    16. </view>
    17. </view>
    18. </view>

    代码示例 2:搜索历史

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • JS
    
     
    1. Page({
    2. data: {
    3. value: '',
    4. queryArr: []
    5. },
    6. valueInput(e) {
    7. this.setData('value', e.detail.value);
    8. },
    9. storageQuery() {
    10. let value = this.getData('value');
    11. let queryArr = this.getData('queryArr');
    12. if (value) {
    13. // 若输入的存储数据与之前相同,则去重
    14. const index = queryArr.findIndex(item => item === value);
    15. if (index > -1) {
    16. queryArr.splice(index, 1);
    17. }
    18. // 添加存储数组中的值
    19. queryArr.unshift(value);
    20. this.setData({queryArr});
    21. }
    22. const storeArr = queryArr.slice(0, 20);
    23. swan.setStorageSync('queryData', storeArr);
    24. },
    25. clearQuery() {
    26. swan.removeStorageSync('queryData');
    27. this.setData('queryArr', []);
    28. console.log('搜索历史清空成功');
    29. }
    30. });

    错误码

    Android

    错误码 说明

    201

    解析失败,请检查调起协议是否合法

    1001

    执行失败

    iOS

    错误码 说明

    202

    解析失败,请检查参数是否正确

    赞(0) 打赏
    未经允许不得转载:九八云安全 » 九八云百度小程序教程:swan.removeStorage

    评论 抢沙发