I have a contenteditable
div
and use v-html
to add the raw html including the click event. But in this case the click event doesn't work. Inspecting the element shows there is a click event on the div but it still doesn't work.
If I hardcode any other div with click event in contenteditable
div
then it works. Don't know if I'm doing this right.
:
<div id="div_textarea2" v-html="temp_testing_div2" contenteditable="true"></div> data () { return { temp_testing_div2: `<div @click="ClickLine">Click this</div>`, } } ClickLine(){ alert("Clicked"); }
@HermantSah
v-html
will not bind any Vue instructions, such as the@click
event. See the documentation here.A workaround might be to set a
@click
event on the parent div and give the element something distinguishable, such as an id, in the template string.You can then intercept that event and check which element was clicked. If the element matches an element in the template string, do something, etc. Here's a rough example.
It all feels a bit confusing to me. There may be an easier way to achieve your wish.