Answers for "vuejs v-model custom component"

2

how to access both child event param and parent param in vue

<template>
    <ul>
        <product v-for="product in products"
                 :product="product"
                 @add="addToChart" />
    </ul>
</template>

<script>
const Product = {
    props: ["product"],
    render(h) {
        return h("li", { on: { click: this.click } }, this.product);
    },
    methods: {
        click() {
            this.$emit("add", { product: this.product, quantity: 42 });
        }
    }
};

export default {
    data() {
        return {
            products: ["Foo", "Bar"]
        };
    },
    components: {
        Product
    },
    methods: {
        addToChart({ product, quantity }) {
            console.log(product, quantity);
        }
    }
}
</script>
Posted by: Guest on April-30-2020
9

vue v-model

<input v-model="message" placeholder="edit me">
<p>Message is: {{ message }}</p>
Posted by: Guest on March-04-2020
0

what does v-model do in vue

Although a bit magical, v-model is essentially syntax sugar for updating 
data on user input events, plus special care for some edge cases.
Posted by: Guest on August-16-2020

Browse Popular Code Answers by Language