Answer the question
In order to leave comments, you need to log in
Vue.js: On-the-fly recompilation after dom changes. How?
Hello. I ask for help, because I myself could not figure it out.
There is a code:
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="vue">
<ul id="target">
<li>
<a href="#" v-on:click.prevent="alert">Alert method (triggered)</a>
</li>
</ul>
<a href="#" v-on:click.prevent="appendElem">Append element</a>
</div>
new Vue({
el: '#vue',
methods: {
alert: function (event) {
alert("Ok, i`m is triggered )");
return;
},
appendElem: function (event) {
html = '<li><a href="#" v-on:click.prevent="alert">Alert method (not triggered)</a></li>';
document.getElementById('target').insertAdjacentHTML('beforeEnd', html);
// вот тут как-то сказать vue, что нужно закомпилить изменения?
return;
},
}
});
Answer the question
In order to leave comments, you need to log in
You have jquery, brain. If after the first click you need to change the message, then you need to change the message after the first click, something like this:
<div id="vue">
<div id="target">
<a href="#" v-on:click.prevent="alert">{{message}}</a>
</div>
</div>
new Vue({
el: '#vue',
data: {
message: 'alert 1'
},
methods: {
alert: function (event) {
alert(this.message);
this.message = 'alert 2';
}
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question