代码拉取完成,页面将自动刷新
import { router } from '@kit.ArkUI';
import { MockSetup } from '@ohos/hamock';
import { CacheUtil, ToastUtil } from '@pura/harmony-utils';
import { TitleBarView } from '../../component/TitleBarView';
import { DescribeBean } from '../../model/DescribeBean';
/**
* "缓存工具类
*/
@Entry
@Component
struct Index {
private scroller: Scroller = new Scroller();
@State describe: DescribeBean = router.getParams() as DescribeBean;
@MockSetup
mock() {
this.describe = new DescribeBean("CacheUtil", "缓存工具类");
}
build() {
Column() {
TitleBarView({ describe: this.describe })
Divider()
Scroll(this.scroller) {
Column() {
Button("put()")
.btnStyle()
.onClick(() => {
CacheUtil.put("pwd", "ABCD@12345");
ToastUtil.showToast("缓存密码成功");
})
Button("get()")
.btnStyle()
.onClick(() => {
let pwd = CacheUtil.get<string>("pwd");
ToastUtil.showToast(`取值:${pwd}`);
})
Button("has()")
.btnStyle()
.onClick(() => {
let pwd = CacheUtil.has("pwd");
ToastUtil.showToast(`缓存是否存在:${pwd}`);
})
Button("remove()")
.btnStyle()
.onClick(() => {
CacheUtil.remove("pwd");
ToastUtil.showToast(`缓存移除成功!`);
})
Button("isEmpty()")
.btnStyle()
.onClick(() => {
let blEmpty = CacheUtil.isEmpty();
ToastUtil.showToast(`缓存是否为空:${blEmpty}`);
})
Button("clear()")
.btnStyle()
.onClick(() => {
CacheUtil.clear();
ToastUtil.showToast(`清除缓存数据成功`);
})
Blank().layoutWeight(1)
}
.margin({ top: 5, bottom: 5 })
}
.layoutWeight(1)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Start)
.backgroundColor($r('app.color.main_background'))
}
}
@Styles
function btnStyle() {
.width('90%')
.margin({ top: 10, bottom: 2 })
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。