Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

345
Visualizações
Styling active item in a <b-list-group> (vue.js)

I'm fairly new to vue.js and currently trying to style a specific item of a list group. My application is separated into a main nav, a side menu and a main content section. Clicking on an item in the list group supposedly highlights the clicked item and changes the main content. Changing the content works fine but I'm struggling with styling the item in the list. The code of the component for the side menu looks like this:

<div id="app">
<div>
    <b-list-group>
        <b-list-group-item 
            v-for="item in this.items" 
            v-on:click="selectItem(item.id)"
            :key="item.id" 
            class="item-selection">
                {{item.title}}
        </b-list-group-item>
    </b-list-group>
</div>
</div>

The 'items' array i'm getting the item from is stored in the vuex store and accessing everything works fine. I know you can set an individual item of a list group to "active", but since I'm getting my items from an array using a for-each construction, I could not figure out how to do that in my case. I tried to use a conditional class like this:

v-bind:class="{'item-selection':true, 'active-item':(item.id === this.currentItem)}"

but this just results in the items not even showing when starting the application. ('currentItem' is the index of the currently selected item which is also stored in the vuex store). The class 'item-selection' is just used for the general styling of the items (worked fine before adding the conditions) and is therefore hard coded true, the 'active-item' class I wanted to use for the highlighting.

Do you guys have any suggestions? Am I missing something (trivial)?

edit:

javascript:

new Vue({
  el: '#app',
  data: {
    items :[
      {id: 0,
       title: 'first item'},
       {id: 1,
       title: 'second item'},
       {id: 2,
       title: 'third item'}
    ],
    currentItem : 0
  },
  methods: {
    selectItem(id){
      currentItem = id;
    }
  }
})

css:

.item-selection:hover{
  color: black;
  cursor: pointer;
  background: #ebebeb;
}

.item-selection{
  background-color: #ffffff;
}

.active-item{
  background-color: #444444;
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

v-bind:class="{'item-selection':true, 'active-item': item.id === currentItem}"


methods: {
  selectItem(id){
    this.currentItem = id;
  }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda