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

188
Visualizações
How to delete particular array by selecting checkbox and delete array in Vuejs?

<script>
import { datalist } from "./datalist";
export default {
  name: "HelloWorld",
  components: {},
  data() {
    return {
      items: datalist,
    };
  },
  methods: {
    deleteEvent(id) {
      this.items = this.items.filter((e) => e.id !== id);
    },
  },
};
</script>
My data...
export const datalist = [
  { id: 1, val: "11", kk: "potter" },
  { id: 2, val: "22", kk: "james" },
  { id: 3, val: "55", kk: "limda" },
  { id: 4, val: "77", kk: "stepen" }
];
 
  <div>
    <div v-for="item in items" :key="item.id">
      <b>{{ item.id }}.</b> &nbsp;&nbsp;&nbsp;
      <router-link :to="{ name: 'UserWithID', params: { id: item.id } }">
        {{ item.kk }}
      </router-link>
      <input type="checkbox" :value="item.id" />
      <button @click="deleteEvent(item.id)">Delete</button>
    </div>
  </div>

My complete code;- https://codesandbox.io/s/wild-flower-rssg0?file=/src/components/datalist.js

I want to delete the array item, When user click on checkbox beside each item. and then click on delete button then the array item record need to be deleted.

But now i am getting as, Directly if I click on delete button, i am able to delete the array. But that should happen only after the checkbox click and then delete button.

For this process, I have taken click event in button and added a method to delete array record but its not working.... Can u please help me what is wrong with the code...

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

0

You should maintain an array of items to delete. Bind the checkbox to this array so that if the checkbox is checked, the item ID is added to this array. Then, simply add a delete button somewhere to delete all selected items.

See example here: https://codesandbox.io/s/elated-lake-ws2wn

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