• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Event Parameter
2
3A 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:
4
5```
6<!-- comp.hml -->
7<div class="item">
8   <text class="text-style" onclick="childClicked">Click here to view the hidden text.</text>
9   <text class="text-style" if="{{showObj}}">hello world</text>
10</div>
11```
12
13```
14// comp.js
15export default {
16  childClicked () {
17     this.$emit('eventType1', {text: 'Receive the parameters from the child component.'});
18    this.showObj = !this.showObj;
19  },
20}
21```
22
23In the following example, the child component passes the  **text**  parameter to the parent component, and the parent component obtains the parameter through  **e.detail**:
24
25```
26<!-- xxx.hml -->
27<div class="container">
28   <text>Parent component: {{text}}</text>
29   <comp @event-type1="textClicked"></comp>
30</div>
31```
32
33```
34// xxx.js
35export default {
36  data: {
37     text: 'Start',
38  },
39  textClicked (e) {
40    this.text = e.detail.text;
41  },
42}
43```
44
45