当前位置:网站首页>#夏日挑战赛# HarmonyOS - 实现带日期效果的待办事项
#夏日挑战赛# HarmonyOS - 实现带日期效果的待办事项
2022-06-24 15:36:00 【51CTO】
作者:俞才彬
前言
初学鸿蒙JS开发技术不久,想要快速结合官方文档上手鸿蒙JS组件开发,本文主要结合HarmonyOS官网上的相关组件及API实现一个根据日期持久化存储待办事项。
效果演示

实现步骤
1. 确定两个页面
首先确定有两个页面:选择日期页面、待办事项页面。选择日期页面将选择的日期如:'2022-6-16' 作为路由参数传递到代办事项页,后者把这个日期作为缓存的key去取数据,并渲染在页面上。
2. 选择日期页面
页面结构如下:
样式如下:
时间选择器使用picker组件,type设置为date,默认值为今天。选择日期时,触发onchange事件,拿到选择的日期,点击确定后,跳转至待办事项页面,并将日期作为路由参数传递。
3. 待办事项页面
3.1 进入待办事项页面
进入待办事项页面需要根据路由参数(传递的日期)判断是否是今天,是今天则展示动态的数字时钟。
还需要根据路由参数从缓存中读取待办事项数据,并设置给list,用于页面展示。调用官网API的storage.get()方法,由于后续修改数据可能涉及多层回调,考虑到代码可读性,将从缓存中读数据操作用Promise封装。
3.2 分别展示全部、未完成、已完成待办事项
使用tabs组件和列表组件list渲染分别展示全部、未完成和已完成待办事项。
若无数据,全部区域展示 “请先添加今天的待办事项吧!”,已完成和未完成区域展示无数据图片。
在计算属性中计算全部、未完成、已完成的个数,用于tabs展示。
3.3 添加待办事项
在输入框中输入内容,点击添加按钮,添加待办事项,并调用storage.set()API将list存在缓存中,成功之后更新list以更新视图。若输入框无内容,使用prompt.showToast提示输入内容。
3.4 完成 / 取消待办事项
点击选择框,勾选或者取消勾选待办事项,并设置缓存。
3.5 删除待办事项
使用piece组件的onclose事件删除待办事项,删除前使用prompt.showDialog弹窗方法询问是否删除,点击确认后删除,并设置缓存。
总结
以上就是完成带日期缓存效果的待办事项的全部过程了,算是对鸿蒙JS开发快速上手的初步认识吧, 后期还可以对其完善,比如在样式、功能方面等等,希望可以和大家共同学习鸿蒙更多的知识,一起进步。
更多原创内容请关注: 中软国际 HarmonyOS 技术团队
入门到精通、技巧到案例,系统化分享HarmonyOS开发技术,欢迎投稿和订阅,让我们一起携手前行共建鸿蒙生态。
边栏推荐
- 60 个神级 VS Code 插件!!
- Logging is not as simple as you think
- 【Prometheus】5. Alertmanager alarm (incomplete)
- Precautions for using JMeter suite to build a pressure test environment
- 我与“Apifox”的网络情缘
- Remote connection raspberry pie in VNC Viewer Mode
- Nature刊登量子计算重大进展:有史以来第一个量子集成电路实现
- leetcode 139. Word Break 單詞拆分(中等)
- I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15
- From practical teaching to competition exercise, Tencent experts personally teach Ti-One platform operation strategy!
猜你喜欢

【面试高频题】难度 3/5,可直接构造的序列 DP 题
![[download attached] installation and simple use of Chinese version of awvs](/img/3b/f26617383690c86edff465c9a1099e.png)
[download attached] installation and simple use of Chinese version of awvs

How to expand disk space on AWS host

构建Go命令行程序工具链

Logging is not as simple as you think

Understanding openstack network

Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES

国产最长寿的热销手机,苹果也不是对手,总算让国产手机找回面子

Linux记录-4.22 MySQL5.37安装(补充)

高速公路服务区智能一体机解决方案
随机推荐
The cold winter can't stop the determination to enter the big factory. The Android interview has a complete knowledge structure, and everything you need to master in the interview is here!
My network relationship with "apifox"
Detailed explanation of estab of Stata regression table output
How to efficiently transfer enterprise business data?
A new weapon to break the memory wall has become a "hot search" in the industry! Persistent memory enables workers to play with massive data + high-dimensional models
Database tools in intelij can connect but cannot display schema, tables
刚刚阿里面软件测试回来,3+1面任职阿里P7,年薪28*15薪
Linux记录-4.22 MySQL5.37安装(补充)
我与“Apifox”的网络情缘
MySQL toolset: the official performance testing tool mysqlslap
Poor remote code execution in Alien Swarm
设备通过国标GB28181接入EasyCVR平台,出现断流情况该如何解决?
Two problems of qtreewidget returning as DLL in singleton mode
如何实现容器内的SqlServer的数据库迁移
Golang+redis distributed mutex
Design of CAN bus controller based on FPGA (Part 2)
Logging is not as simple as you think
One article explains Jackson configuration information in detail
Using oasis to develop a hop by hop (I) -- Scene Building
April 23, 2021: there are n cities in the TSP problem, and there is a distance between any two cities