当前位置: 首页 > news >正文

常平网站公司网站费用怎么做会计分录

常平网站,公司网站费用怎么做会计分录,wordpress get_term,厦门今天刚刚发生的新闻前言: 这篇博客会列举鸿蒙开发中父组件调用子组件的三种方案,相信你在看完以后会有所收获。 还是老样子,我们跟着官方文档学习与实践,链接如下: https://developer.huawei.com/consumer/cn/doc/best-practices/bpta-u…

前言:

这篇博客会列举鸿蒙开发中父组件调用子组件的三种方案,相信你在看完以后会有所收获。

还是老样子,我们跟着官方文档学习与实践,链接如下:

https://developer.huawei.com/consumer/cn/doc/best-practices/bpta-ui-component-encapsulation#section1186112410119https://developer.huawei.com/consumer/cn/doc/best-practices/bpta-ui-component-encapsulation#section1186112410119根据官方文档提供的思路,我们便可结合现有的知识与经验动手练一练。

本人实践后整理的运行效果图和代码如下:

方案一:

利用装饰器@State 与 @Prop 的状态变量单项绑定特性
父组件的message传递给子组件,父组件修改父组件的message,子组件监听message,并执行方法。

1、Index.ets

import { Method01 } from "./Method01";@Entry
@Component
export struct Index {build() {Column() {Method01()}}
}

2、Method01.ets

// 方案一:利用装饰器@State 与 @Prop 的状态变量数据绑定特性
// 父组件的message传递给子组件,父组件修改父组件的message,子组件监听message,并执行方法
@Component
export struct Method01 {@State message: string = "这是一个父组件"@State childMessage: string = ""build() {Column({ space: 20 }) {Text("调用子组件方法示例").padding(30)Button(this.message).onClick(() => {const child = "修改"this.childMessage = child})Child({ propMessage: this.childMessage })}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}// 子组件
@Component
struct Child {@Watch("childClick") @Prop propMessage: string = ""@State message: string = "这是一个子组件"childClick() {this.getUIContext().showAlertDialog({ message: this.message })}build() {Column() {Text(this.message).onClick(() => {console.log("click")})}}
}

方案二:

通过 Controller 类实现父组件 与子组件 的通信。

子组件将自身 action 方法赋值给父组件传入的 controller 实例;父组件点击按钮时调用该 controller 的 action 方法,会触发子组件显示包含自身 message 的弹窗。

1、Index.ets

import { Method01 } from "./Method01";
import { Method02 } from "./Method02";@Entry
@Component
export struct Index {build() {Column() {Method02()}}
}

2、Method02.ets

class Controller {action = () => {};
}@Component
export struct Method02 {@State message: string = "这是一个父组件"actionController: Controller = new Controller()build() {Column({ space: 20 }) {Text("调用子组件方法示例 02").padding(30)Button(this.message).onClick(() => {this.actionController?.action()})Child({ controller: this.actionController })}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}@Component
export struct Child {@State message: string = "这是一个子组件"controller: Controller | undefined = undefined;aboutToAppear(): void {if (this.controller) {this.controller.action = this.action}}action = () => this.getUIContext().showAlertDialog({ message: this.message })build() {Column() {Text(this.message)}}
}

方案三:

使用emitter通信。

父组件 通过使用 emitter 触发指定 ID 的事件;子组件 监听该事件并触发指定方法,并在销毁时移除事件监听。

1、Index.ets

import { Method01 } from "./Method01";
import { Method02 } from "./Method02";
import { Method03 } from "./Method03";@Entry
@Component
export struct Index {build() {Column() {Method03()}}
}

2、Method03.ets

import { emitter } from "@kit.BasicServicesKit";const EMITTER_ID = "Method03";// 父组件 Method03 通过点击按钮使用 emitter 触发指定 ID 的事件;子组件 Child 监听该事件以显示弹窗,并在销毁时移除事件监听。
@Component
export struct Method03 {@State message: string = "这是一个父组件"build() {Column({ space: 20 }) {Text("调用子组件方法示例 03").padding(30)Button(this.message).onClick(() => {emitter.emit(EMITTER_ID);})Child()}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}@Component
export struct Child {@State message: string = "这是一个子组件";action = () => {this.getUIContext().showAlertDialog({ message: "这是一个子组件" })}aboutToAppear(): void {emitter.on(EMITTER_ID, this.action);}aboutToDisappear(): void {emitter.off(EMITTER_ID);}build() {Text(this.message)}
}

有帮助就给个关注、收藏或赞吧

http://www.dtcms.com/a/587305.html

相关文章:

  • 兰州网站建设与优化wordpress 关键词屏蔽
  • 凡科网站建设注册学校学院网站建设目标
  • h5网站制作平台网站备案 网站建设方案书
  • 潮州网站建设上海嘉定网站建设公司
  • Data Sink定义、参数与可落地示例
  • 青岛网站设计网站wordpress 评论 邮箱
  • 杭州论坛网站制作diy电子商城网站
  • 做网站页面需要的资料安徽建设工程网
  • 网站建设中需要注意的问题高清短视频素材库无水印
  • 手机网站与pc网站同步广东茂名网站建设
  • 网站安全狗 拦截301xly000.WordPress.cok
  • 确山专业网站建设南昌师范学院网站建设的意义和目的
  • 权威的网站制作视频解析网站怎么做的
  • 公司注册网站官网郑州网站开发公司
  • 云南网站设计定制找网页设计公司去哪个平台
  • 网页设计与网站建设电话湖南建筑网
  • 网站升级建设方案开发公司网站建设
  • 阿里云有域名之后怎么建设网站我要招人在哪个网站招
  • python 做网站怎样潍坊美丽乡村建设一般发了哪个网站
  • 十大网站建立公司小程序宣传推广方案
  • 第1章 GIS基础入门
  • FPGA教程系列-Vivado IP核DDS核
  • 网站设计参考网站网站建设 费用 入哪个科目
  • 郑州企业网站建设网站制作公司网址
  • 淘宝网站建设退款wordpress应用和lamp
  • 分享一个基于微信小程序的网络安全知识科普平台的设计与实现,网络安全教育智能答疑小程序|在线测试科普宣传小程序
  • 济宁建设局官方网站网站建设与运行
  • 搭建一个公司网站常州设计网站
  • 比特币交易所网站开发黄页网站推广app软件
  • 怎样做站长建网站达州seo