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

399
Visualizações
I want to change the color of the <li> with a select option using vue.js

I'm new to vue.js and I am trying to change the background color using the select option. I tried this method cueCardsColor but still nothing happens

<ul>
  <li :class="+ cueCardColor"> 
    <select v-model="selected">
      <option v-for="option in options" v-bind:value="option.value">
        {{ option.text }}
      </option>
    </select>
  </li>
</ul>

here are the values and the method

new Vue({
  el: '...',
  data: {
    selected: 'Select color',
    options: [
      { text: 'Green', value: 'green' },
      { text: 'Red', value: 'red' },
      { text: 'Blue', value: 'blue' }
    ]
  },
computed:{
 cueCardColor() {
      if(this.selected!='Select color'){
        return this.selected.options
      }
    
    }

}
})

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You already have the color in this.selected:

new Vue({
  el: '#app',
  data: {
    selected: 'Select color',
    options: [
      { text: 'Green', value: 'green' },
      { text: 'Red', value: 'red' },
      { text: 'Blue', value: 'blue' }
    ]
  },
computed:{
 cueCardColor() {
      if(this.selected!='Select color'){
        return this.selected
      }
      return 'transparent'
    }

}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<ul>
  <li :style="{ 'background-color': cueCardColor }"> 
<select v-model="selected">

  <option v-for="option in options" v-bind:value="option.value">
    {{ option.text }}

  </option>

</select>
</li>
</ul>
</div>

about 4 years ago · Juan Pablo Isaza 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