Answers for "vuejs data"

45

vue lifecycle hooks

<script>
  export default {
    beforeCreate() {
      console.log("beforeCreate")
    },
    created() {
      console.log("created")
    },
    beforeMount() {
      console.log("beforeMount")
    },
    mounted() {
      console.log("mounted")
    },
    beforeUpdate() {
      console.log("beforeUpdate")
    },
    updated() {
      console.log("updated")
    },
    beforeDestroy() {
      console.log("beforeDestroy")
    },
    destroyed() {
      console.log("destroyed")
    }
  }
</script>
Posted by: Guest on June-07-2020
0

vue data

data: function () {
  return {
    count: 0
  }
}
Posted by: Guest on July-22-2021
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

Code answers related to "Javascript"

Browse Popular Code Answers by Language