后浪云百度小程序教程:swan.clearStorageSync
- swan.clearStorageSync
- 方法参数
- 示例
- 图片示例
- 代码示例
- Bug & Tip
- 错误码
- Android
- iOS
swan.clearStorageSync
解释:同步清理本地数据缓存。
方法参数
无
示例
跳转编辑工具
在开发者工具中打开
在 WEB IDE 中打开
扫码体验
代码示例

请使用百度APP扫码
图片示例

代码示例
- JS
clearStorage() {let res = swan.clearStorageSync();// 基础库 3.140.1 之前,无法判断接口是否调用失败// 基础库 3.140.1 及以后,通过 instanceof 来判断接口是否调用失败if (!(res instanceof Error)) {this.toast('后台数据已清除', 'none');this.setData('disabled', true);}else {console.log('clearStorageSync fail', res.message);}}// 其余代码部分与 swan.clearStorage(https://smartprogram.baidu.com/docs/develop/api/storage/remove_swan-clearStorage/) 相同
Bug & Tip
- Tip:基础库 3.140.1 之前,无法判断接口是否调用失败。
- Tip:基础库 3.140.1 及以后,接口调用失败时会返回一个标准的
Error对象,可通过instanceof来判断接口是否调用失败。
错误码
Android
| 错误码 | 说明 |
|---|---|
1001 | 执行失败 |
iOS
| 错误码 | 说明 |
|---|---|
202 | 解析失败,请检查参数是否正确 |
版权声明:
作者:后浪云
链接:https://idc.net/help/186642/
文章版权归作者所有,未经允许请勿转载。
THE END
