简体   繁体   English

在新创建的元素上绑定功能

[英]Bind function on newly created element

I want to create new html element with v-on call. 我想用v-on调用创建新的html元素。 However after I call function pasted below the v-on is not rendered so nothing happens after click. 但是,在我调用粘贴在v-on下方的函数之后,将不会呈现,因此单击后无任何反应。 Is there anyway I can force vue to re-render this element? 无论如何,我可以强迫Vue重新渲染此元素吗?

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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