0👍
Try this out.
<div onclick="window.alert(${this.myID})"></div>
0👍
Do not mutate DOM directly!
This is really, really important for FE frameworks like Vue. While mutating the DOM directly is possible, it’s going to cause all kinds of problems.
Before addressing how to add an onclick
listener, you should consider what your goal is and then pick the solution for your needs.
Most likely you can solve this within the template syntax. If not, you can also use JSX or render functions. If there is a particular reason why you need to include something like dom.innerHTML
, can you include it in the question?
Source:stackexchange.com