admin管理员组文章数量:1185210
I have multiple list items that I want to toggle active classes on when they are being clicked on.
<ul class="list-body">
<li v-on="click: setFilter('style', 'pils')" v-class="active: isActive">Pils</li>
<li>Dubbel</li>
<li>Tripel</li>
<li v-on="click: setFilter('style', 'Quadrupel')">Quadrupel</li>
<li>Wit</li>
</ul>
I already have a setFilter
click function where I can add extra functionality to activate the class onClick
.
setFilter: function(facet, value) {
// Facet for style of beer(search filter)
this.helper.addDisjunctiveFacetRefinement(facet, value).search();
},
My question is how can select the specific li
element that was clicked on and called the with setFilter
method?
I want to set a variable for the active class false
or true
for each single li
element that has been clicked (or not clicked).
I have multiple list items that I want to toggle active classes on when they are being clicked on.
<ul class="list-body">
<li v-on="click: setFilter('style', 'pils')" v-class="active: isActive">Pils</li>
<li>Dubbel</li>
<li>Tripel</li>
<li v-on="click: setFilter('style', 'Quadrupel')">Quadrupel</li>
<li>Wit</li>
</ul>
I already have a setFilter
click function where I can add extra functionality to activate the class onClick
.
setFilter: function(facet, value) {
// Facet for style of beer(search filter)
this.helper.addDisjunctiveFacetRefinement(facet, value).search();
},
My question is how can select the specific li
element that was clicked on and called the with setFilter
method?
I want to set a variable for the active class false
or true
for each single li
element that has been clicked (or not clicked).
1 Answer
Reset to default 28You can directly pass the event and the events target in your function. The target is the element you clicked on.
HTML:
<ul id="demo">
<li v-on="click: onClick">Trigger a handler</li>
<li v-on="click: n++">Trigger an expression</li>
</ul>
JS:
var vue = new Vue({
el: '#demo',
data: {},
methods: {
onClick: function (e) {
var clickedElement = e.target;
}
}
})
With your element you can do what you want. For example, if you use jQuery:
$(clickedElement).siblings().removeClass('active');
$(clickedElement).addClass('active');
本文标签: javascriptVuejs getting the element that is being called by an eventStack Overflow
版权声明:本文标题:javascript - Vuejs getting the element that is being called by an event? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738312852a2074139.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论