[Vuejs]-How to add a class to the right navigation element based on a string if Vue.js :class='' takes a boolean?

1👍

I think it is pretty simple

<nav class='navigation'>
 <div :class="{ active: activeSection==test1 }" @click='scrollTo(".test1")'> 
 </div>
 <div :class="{ active: activeSection==test2}" @click='scrollTo(".test2")'> 
</div>
<div :class="{ active: activeSection==test3}" @click='scrollTo(".test3")'> 
</div>
<div :class="{ active: activeSection==test4}" @click='scrollTo(".test4")'> 
</div>
</nav>

and you need to update value of activeSection on scrollTo method as well
https://v2.vuejs.org/v2/guide/class-and-style.html

Leave a comment