1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
event-parameter.md 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

Event Parameter

A child component can also pass parameters to an upper-layer component through the bound event. The following example describes how to pass parameters through the custom event:

<!-- comp.hml -->
<div class="item">  
   <text class="text-style" onclick="childClicked">Click here to view the hidden text.</text> 
   <text class="text-style" if="{{showObj}}">hello world</text> 
</div>
// comp.js
export default { 
  childClicked () {
     this.$emit('eventType1', {text: 'Receive the parameters from the child component.'});
    this.showObj = !this.showObj;
  },
}

In the following example, the child component passes the text parameter to the parent component, and the parent component obtains the parameter through e.detail:

<!-- xxx.hml -->
<div class="container">  
   <text>Parent component: {{text}}</text> 
   <comp @event-type1="textClicked"></comp>  
</div>
// xxx.js
export default { 
  data: {
     text: 'Start',
  },
  textClicked (e) {
    this.text = e.detail.text;
  },
}
1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891