HarmonyOS应用开发第一次作业笔记

目录

1、根据P6视频做出做出记事本删除添加案例 

2.目录

3.组件


1、根据P6视频做出做出记事本删除添加案例 

export default {
    data: {
        todoList:[
         {
            info:'给老王打个电话',
            status : true
        },
        {
            info:'输出工作计划',
            status : false
        },
        {
            info:'和小王对接需求',
            status : true
        },
        {
            info:'整理客户资料',
             status : false
        },
         {
             info: '和朋友一起聚餐',
             status: false
         }
        ]
    },
    onInit() {
        this.title = this.$t('strings.world');
    },
    remove(index){
    console.log(index)
    this.todoList.splice(index,1);
    },
    switchChange(index){
    this.todoList[index].status = !this.todoList[index].status
    },
    addTodo(){
        this.todoList.push({
            info: 'IDE工具无法监听键盘输入',
            status: false
            })
    },
    computed :{
        todocount(){
            let num =0;
            this.todoList.forEach(element => {
                if( !element.status){
                    num++
                }
        });
        return num
        }
    }
}
.container {
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-bottom : 100px;
}
.title {
    font-size: 25px;
    margin-top: 20px;
    margin-bottom: 20px;
    color: #000000;
    opacity: 0.9;
    font-size: 28px;
}
.item {
    width: 325px;
    padding: 10px 0;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    border-bottom: 1px solid #eee;
}
.todo {
    color: #000;
    width: 180px;
    font-size: 18px;
}
.switch{
    font-size: 12px;texton-color: green;textoff-color : red;text-padding : 5px;width: 100px;
    height: 24px;
    allow-scale: false;
}
.remove {
    font-size: 12px;
    margin-left: 10px;
    width: 50px;
    height: 22px;
    color: #fff;
    background-color: red;
}
.info {
    width: 100%;
    margin-top: 10px;
    justify-content: center;
}
.info-text{
    font-size: 18px;
    color: #AD7A1B;
}
.info-num {
    color: orangered;
    margin-left: 10px;
    margin-right: 18px;
}
.add-todo {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 108%;
    height: 68px;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    background-color: #ddd;
}
.plan-input{
    width: 248px;height: 40px;
    background-color : #fff;
}
.plan-btn {
    width: 90px;
    height: 35px;
    font-size: 15px;
}
<div class="container">
    <text class="title">待办事项</text>
    <div class="item" for="{{todoList}}">
        <text class="todo">{{$item.info}}</text>
        <switch showtext="true" checked="{{$item.status}}"
            texton="完成" textoff="待办"
            class="switch"
            @change="switchChange($idx)"></switch>
        <button class="remove" @click="remove($idx)">删除</button>
    </div>
    <div class="info">
        <text class="info-text">您还有</text>
        <text class="info-num">{{todocount}}</text>
        <text class="info-text">件事情待办,加油! </text>
    </div>
    <div class="add-todo">
        <input class="plan-input" type="text"></input>
        <button class="plan-btn" onclick="addTodo" @click="addTodo">添加待办</button>
    </div>
</div>

2.目录

JS FA 应用的 JS 模块 (entry/src/main/js/module) 的典型开发目录结构如下:

 目录结构中文件分类如下:

  • .hml 结尾的 HML 模板文件,这个文件用来描述当前页面的文件布局结构。
  • .css 结尾的 CSS 样式文件,这个文件用于描述页面样式。
  • .js 结尾的 JS 文件,这个文件用于处理页面和用户的交互。

各个文件夹的作用:

  • app.js 文件用于全局 JavaScript 逻辑和应用生命周期管理。
  • pages 目录用于存放所有组件页面。
  • common 目录用于存放公共资源文件,比如:媒体资源和 JS 文件。
  • i18n 目录用于配置不同语言场景资源内容,比如:应用文本词条,图片路径等资源,注意 i18n 是开发保留文件夹,不可重命名。

3.组件

  1. 组件(Component)是构建页面的核心,每个组件通过对数据和方法的简单封装,实现独立的可视、可交互功能单元。组件之间相互独立,随取随用,也可以在需求相同的地方重复使用。

  2. 鸿蒙 JS API 提供了完善的组件介绍,详细情况我们去查阅一下官方文档: 组件 - 官方介绍

  3. 根据组件的功能,可以分为以下四大类:

组件类型主要组件
基础组件text、image、progress、rating、span、marquee、image-animatordivider、search、menu、chart
容器组件div、list、list-item、stack、swiper、tabs、tab-bar、tab-content、list-item-group、refresh、dialog
媒体组件video
画布组件canvas

鸿蒙系统组件相较于其他前端组件仓库,给咱们专门封装了一个 chart 组件,图表组件,用于呈现线形图、柱状图、量规图界面。

官方文档地址

使用 chart 组件进行体验,具体执行步骤如下:

  1. 创建 pages.chart 文件夹,包含 chart.hml、chart.js、chart.css 三个文件。
  2. 配置路由,在 config.json 这个文件里面。

  1. 预览页面时,务必要注意打开当前需要预览的页面文件夹下 hml、css、js 任意一个文件。
  2. 切换页面进行预览,不需要重新启动预览器,直接点击右上角刷新按钮即可,出现错误提示。

  1. 使用模拟器进行模拟的时候,编辑器工具会自动打包输出 hap 文件,模拟器直接加载运行该文件,模拟器不支持热更新,预览器预览会输出编译后文件,支持热更新,也支持多设备同时预览。 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

某科学的初学者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值