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

98
Visualizações
How would I make the button hide the incomplete tasks

This is the Jsfiddle: https://jsfiddle.net/zxo35mts/1/

Essentially I'm trying to make the button hide all incomplete tasks when clicked and show them again when clicked again yet i have no idea what to do

<div id="root">

    <h1>
        All Tasks
    </h1>

    <ul>
        <li v-for="task in tasks" v-text="task.description"></li>
    </ul>
    <button @click="hideIncompleteTasks">show only completed</button>

</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>

<script>
    new Vue({

        el: "#root",

        data: {

            tasks: [

                { description: "go to the store", completed: true },
                { description: "finish screencast", completed: false },
                { description: "make donation", completed: false },
                { description: "clear inbox", completed: false },
                { description: "make dinner ", completed: false },
                { description: "clean room", completed: true },

            ]

        },
        methods: {

            hideIncompleteTasks() {
                if (!this.tasks.completed) {

                }
            }

        },

    })
</script>
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Add another property called showCompleted which could be updated by the button click event, then add another computed property called shownTasks based on the first property :


    new Vue({

        el: "#root",

        data: {

            tasks: [

                { description: "go to the store", completed: true },
                { description: "finish screencast", completed: false },
                { description: "make donation", completed: false },
                { description: "clear inbox", completed: false },
                { description: "make dinner ", completed: false },
                { description: "clean room", completed: true },

            ],
          showCompleted:false

        },
        computed:{
          shownTasks(){ return this.showCompleted?this.tasks.filter(task=>task.completed):this.tasks;}
        },
        methods: {

            hideIncompleteTasks() {
               this.showCompleted=!this.showCompleted
            }

        },

    })

then render the shownTasks like :


 <ul>
        <li v-for="task in shownTasks" v-text="task.description"></li>
    </ul>
    <button @click="hideIncompleteTasks">show only completed</button>

over 4 years ago · Santiago Trujillo Relatório

0

One way:

new Vue({
  el: "#root",
  data: {
      tasks: [
          { description: "go to the store", completed: true },
          { description: "finish screencast", completed: false },
          { description: "make donation", completed: false },
          { description: "clear inbox", completed: false },
          { description: "make dinner ", completed: false },
          { description: "clean room", completed: true },
      ],
      onlyCompleted: false
  },
  methods: {
    hideIncompleteTasks() {
      this.onlyCompleted = !this.onlyCompleted
    }
  },
})
.hiden {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="root">
      <h1>
          All Tasks
      </h1>
      <ul>
          <li v-for="task in tasks" v-text="task.description" :class="onlyCompleted && !task.completed && 'hiden' "></li>
      </ul>
      <button @click="hideIncompleteTasks">show only completed</button>

  </div>

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