Bind function on newly created element

115 views Asked by At

I want to create new html element with v-on call. However after I call function pasted below the v-on is not rendered so nothing happens after click. Is there anyway I can force vue to re-render this element?

createFromTemplate: function() {
    var el = document.body.appendChild(document.createElement('div'));

    el.innerHTML = '<a href="#" v-on="click: close()"></a>;
},
1

There are 1 answers

0
user2755140 On

The same thing that you do to populate the element:

el.innerHTML = '<a href="#" v-on="click: close()"></a>;

can be done to assign a function:

el.onclick = function() {
    //do stuff
}