N
N
Nik17122017-04-24 13:03:03
JavaScript
Nik1712, 2017-04-24 13:03:03

How to make vue directive work in dynamically added element?

There is a piece of html code that vue.js outputs through the v-html directive with an ajax request
, inside there is a v-on: click directive that calls the method, but it does not work. How to hang an event handler?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Bogdan Dukhevich, 2017-04-27
@Nik1712

You are going against the v-html directive.
It is worth either complicating the template (rejecting v-html), or hanging a handler higher in the DOM on the parent container and checking event.target.

E
Evgeny Kulakov, 2017-04-24
@kulakoff Vue.js

If you have @click inside the resulting fragment, then judging by the dock, it will not work:

Note that the content is pasted as plain HTML - that is, it is not compiled as a Vue template. Don't organize nested templates with v-html, try using components instead.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question