Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  161] [ 2]  / answers: 1 / hits: 16093  / 5 Years ago, mon, april 22, 2019, 12:00:00

I have created two tabs, which I would like the class of active set on the first <li> by default.



Then, when the second tab is selected, the .active class should pass to the second <li> and be removed from the first.



I can use CSS to create some style rules in order to give a visual indicator as to which tab is currently active.



I have also created a JS Fiddle to see the current output.



Any help welcome as I am rather stuck.



<ul class=overlay-panel-actions-primary>
<li v-for=(tab, index) in tabs @click=currentTab = index>{{tab}}</li>
</ul>
<div class=content-bd>
<div class=tab-content>
<div v-show=currentTab === 0>
List of filters options
</div>
<div v-show=currentTab === 1>
List of sort options
</div>
</div>
</div>

new Vue({
el: #app,
data() {
return {
currentTab: 0,
tabs: ['Filter', 'Sort']
};
},
})

More From » vue.js

 Answers
3

Use this -




:class={active: currentTab === index}




<li v-for=(tab, index) in tabs @click=currentTab = index :class={active: currentTab === index}>{{tab}}</li>


Let me know if it works.



Fiddle - https://jsfiddle.net/so3mf8h9/






Update



You can also use ternary operator, It should also work.



:class=currentTab === index ? 'active' : ''

[#52207] Tuesday, April 16, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;