From 1e69399e6e392189b0ec8efcdcb728d42b360754 Mon Sep 17 00:00:00 2001 From: duangavin123 Date: Thu, 4 May 2023 11:46:33 +0000 Subject: [PATCH] update zh-cn/third-party-cases/how-to-bind-different-operations-for-one-component.md. Signed-off-by: duangavin123 Signed-off-by: duangavin123 --- .../how-to-bind-different-operations-for-one-component.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zh-cn/third-party-cases/how-to-bind-different-operations-for-one-component.md b/zh-cn/third-party-cases/how-to-bind-different-operations-for-one-component.md index 3450214bf9..c5d19034e0 100644 --- a/zh-cn/third-party-cases/how-to-bind-different-operations-for-one-component.md +++ b/zh-cn/third-party-cases/how-to-bind-different-operations-for-one-component.md @@ -22,7 +22,7 @@ 1. 创建按钮组件 首先,让我们创建被引用的按钮组件。 这里需要注意的是,由于按钮要绑定不同的处理逻辑,所以我们在点击事件中不要写入固定的处理逻辑,而是传入一个自定义的空方法,该方法的逻辑在父组件中实现,然后传入。具体代码如下: - ``` + ```ts @Component struct ChildComponent{ @State button_text:string = 'hi' @@ -42,7 +42,7 @@ 2. 在父组件中引用按钮组件 接下来,我们在父组件中引用两次第1步中创建的按钮组件。具体代码如下: - ``` + ```ts @Entry @Component struct FuncTransition{ @@ -63,7 +63,7 @@ 3. 在父组件中传入处理逻辑 以上两步已经把我们的页面框架搭好了,接下来就是给按钮组件传入处理逻辑了,这也是最重要的一步。 我们在第1步中为按钮组件的点击事件绑定了一个空函数,现在我们在父组件中创建一个带有具体处理逻辑的函数,并将其传入按钮组件中。在父组件中可以通过为同一函数传入不同参数来为两个按钮组件绑定不同逻辑,也可以通过不同函数来实现,本例中采用前者进行实现。具体代码如下: - ``` + ```ts import router from '@ohos.router' @Entry @Component @@ -96,7 +96,7 @@ ### 完整代码 示例完整代码如下: -``` +```ts import router from '@ohos.router' @Entry @Component -- GitLab