Christian
Christian

Reputation: 26427

How do I listen to an event that's emitted bya ElementUI tree in Vue.js?

I use the ElementUI Tree via:

    <el-tree
            :data="data"
            :props="defaultProps">
    </el-tree>

According, to the documention a node-click event gets emitted when a node is clicked. How do I listen to that event and start a function whenever that happens?

Upvotes: 0

Views: 538

Answers (1)

Michele Riva
Michele Riva

Reputation: 562

Try as follows:

Template:

<el-tree
 :data="data"
 :props="defaultProps"
 @node-click="handleNodeClick"
>
</el-tree>

JavaScript:

methods: {
  handleNodeClick(data) {
    console.log(data);
  }
}

If you want to take a closer look at how it works: https://jsfiddle.net/ncgoswjm/

Bye!

Upvotes: 1

Related Questions