Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!