M
M
mashylapt2022-04-19 22:56:27
Vue.js
mashylapt, 2022-04-19 22:56:27

How to correctly pass a value through emit?

now writes count is not defined

<template>
     <span>{{count}}</span>
     <button @click="addToBasket">btn</button>
</template>>

<script>
    export default {
        name: 'ProductCard',
        props: {
            count: {
                type: Number,
                required: true
            }
        },
        methods: {
            addToBasket(){
                this.$emit('addToBasket', count);          
            }
        }
    }
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
imko, 2022-04-19
@mashylapt

this.$emit('addToBasket', this.count);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question