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

302
Visualizações
Delete function in parent component in vue.js

I have a ticket as you can see in the picture below: enter image description here

I have a delete button as a component and I am trying to add delete functionality to it. I am using this component in my ticket component. So this is my delete component:

<template>
        <div id="delete-button" @click.prevent="removeProductFromCart(item.id)">
            <input type="checkbox" id="checkbox">
            <div id="bin-icon">
                <div id="lid"></div>
                <div id="box">
                    <div id="box-inner">
                        <div id="bin-lines"></div>
                    </div>
                </div>
            </div>
        </div>
    </template>
    
    <script>
    import cartHelper from "../helpers/cartHelper";
    
    export default {
        props: {
            item: Object,
        },
        data() {
            return {
                loading: false,
            };
        },
        methods: {
            removeProductFromCart(id) {
                this.loading = true;
                setTimeout(() => {
                    cartHelper.removeFromCart(id, (response) => {
                        this.$store.dispatch('removeProductFromCart', {
                            cart: response.data,
                        })
                        this.loading = false
                    });
                }, 1000)
            }
        }
    };
    </script>

So the parent component is ticket component:

[![<template>
    <div id="sold-tickets">
        <div class="card">
            <div class="sold-tickets-actions properties">
                <div class="sold-tickets-inner">
                    <DeleteButton :item = "item"  />
                </div>
            </div>
        </div>
    </div>
</template>][1]][1]

<script>
import image from "../../../../img/Hallenbad.jpg";
import DeleteButton from "./DeleteButton";
import cartHelper from "../helpers/cartHelper";

export default {
    props: {
        item: Object,
    },
    components: {DeleteButton},
    data() {
        return {
            image: image,
        };
    },
};
</script>

My problem is, the ticket is being deleted even when I click outside of the child component (Delete component). But I want to use the delete component like a button and I only want to delete the ticket when it is clicked, not outside of the button.

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

0

Try to stop propagation. You probably do not even need the prevent modifier.

@click.prevent.stop='...'
or
@click.stop='...'

If the display type is block, you might also want to inspect the div to see if it is actually filling the entire width of the page. If so, use an inline type, a flex layout, or similiar.

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