我想获取 vue.js 中调用 html 元素以通过 jQuery 修改它。现在,我为每个元素指定类名 + 索引,然后通过 jQuery 调用它,但这看起来像是一个疯狂的 hack。
我想做的事:
new Vue({
el: "#app",
data: {
testFunction : function(element) {
$(element).doSomethingWithIt(); //do something with the calling element
}
}
});
这是调用元素:
<div v-on:click="testFunction(???)">Test</div>
我可以将什么传递到函数中来获取 div 元素,或者是否有其他方法来实现此目的?
您可以像这样从事件中获取元素:
new Vue({
el: "#app",
methods: {
testFunction : function(event) {
$(event.target).doSomethingWithIt();
}
}
});
进而:
<div v-on:click="testFunction">Test</div>
或者(如果你想传递另一个参数):
<div v-on:click="testFunction($event)">Test</div>
[demo] http://jsfiddle.net/kmm53q3a/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)