简体   繁体   中英

Bind function on newly created element

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>;
},

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM