H5微应用JSAPI缓存管理

网友投稿 506 2022-05-30

HWH5.setStorage

HWH5.getStorage

HWH5.clearStorage

HWH5.removeStorage

使用H5微应用JSAPI需要引用资源,查看详细文档

H5微应用JSAPI缓存管理

HWH5.setStorage

设置缓存,暂不支持音频、图片等资源

请求参数

注意:data数据最大存储限制为128KB。

返回结果

无。

请求示例

ES6版本

HWH5.setStorage({   key: 'bulletin_detail_c00299309_10010',   data: '{data:"WeLink is platform"}'}).catch(error => {  console.log('设置缓存异常', error); });

ES5版本

HWH5.setStorage({   key: 'bulletin_detail_c00299309_10010',   data: '{data:"WeLink is platform"}'}).catch(function (error) {  console.log('设置缓存异常', error); });

HWH5.getStorage

获取指定key值的缓存

请求参数

返回结果

请求示例

ES6版本

HWH5.getStorage('bulletin_detail_c00299309_10010')   .then(data => {    console.log(data);   })   .catch(error => {    console.log('获取缓存异常', error);   });

ES5版本

HWH5.getStorage('bulletin_detail_c00299309_10010')   .then(function (data) {    console.log(data);   })   .catch(function (error) {    console.log('获取缓存异常', error);   });

HWH5.clearStorage

清除缓存将会清理当前We码小程序所有的缓存记录

请求参数

无。

返回结果

请求示例

ES6版本

HWH5.clearStorage().then(data => {  console.log(data); }).catch(error => {  console.log('清理本地H5缓存', error); });

ES5版本

HWH5.clearStorage().then(function (data) {  console.log(data); }).catch(function (error) {  console.log('清理本地H5缓存', error); });

HWH5.removeStorage

删除缓存将会删除当前We码小程序指定key值的缓存记录

请求参数

返回结果

请求示例

ES6版本

HWH5.removeStorage('onepice').then(data => {  console.log(data); }).catch(error => {  console.log('删除缓存失败', error); });

ES5版本

HWH5.removeStorage('onepice').then(function (data) {  console.log(data); }).catch(function (error) {  console.log('删除缓存失败', error); });

WeLink

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:《TypeScript实战指南》—1.2.2 npm和 Yarn
下一篇:《Office 2019高效办公三合一从入门到精通 : 视频自学版》 —3.5.2中文版式
相关文章