How to bind click event to HTML button node in Vue Diagram?
This article explains how to bind the click event to an HTML button node in Vue Diagram.
First, create an HTML node with a button. In the Vue Diagram, a button for each HTML node must be provided either as string content or an ng-template to trigger the click event. Below is a code snippet demonstrating how to render the button using an ng-template:
<ejs-diagram
style="display: block"
ref="diagramObject"
id="diagram"
:width="width"
:height="height"
:nodes="nodes"
:nodeTemplate="nodeTemplate"
></ejs-diagram>
data: function () {
return {
nodeTemplate: function () {
return {
template: createApp({}).component('nodeTemplate', NodeTemplate),
};
},
width: '100%',
height: '645px',
nodes: nodes,
};
}
To trigger the click event on the button, add the click event inside the button div element. In the sample below, we have bound the click event, changed the shape to basic, and filled the node color.
<div v-if="data.id == 'node1Template'">
<div id="button" style="width: 100px; height: 100px; background: blue">
<button @click="btnClick">click</button>
</div>
</div>
methods: {
btnClick: function (event) {
diagram.nodes[0].shape = { type: 'Basic' };
diagram.nodes[0].style = { fill: 'red' };
diagram.dataBind();
},
},
Refer to the working sample for additional details and implementation: Sample
Conclusion
We hope you enjoyed learning about how to bind click event to HTML button node in Vue Diagram.
You can refer to our Vue Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, as well as how to quickly get started with configuration specifications. You can also explore our Vue Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!