70
rated 0 times
[
76]
[
6]
/ answers: 1 / hits: 24048
/ 8 Years ago, mon, december 19, 2016, 12:00:00
I am learning Vuejs and I am constantly finding simple things like removing a class to be a pain. Please tell me how I can allow the .active class to be added or removed based on clicks between the 3 links.
In the example below the adding is working fine but it adds .active to all the links, and does not remove when clicked on again.
<div id=app>
<h2>App</h2>
<ul>
<li><a href=# class=link :class={ active: isActive } @click=activeLink>Link text</a></li>
<li><a href=# class=link :class={ active: isActive } @click=activeLink>Link text</a></li>
<li><a href=# class=link :class={ active: isActive } @click=activeLink>Link text</a></li>
</ul>
</div>
JS
var app = new Vue({
el: '#app',
data: {
isActive: false
},
methods: {
activeLink() {
// the line below did not work
// document.getElementsByClassName(active).isActive = false,
this.isActive = true
}
}
})
JSfiddle is here, https://jsfiddle.net/s9r4q0gc/
More From » vuejs2