Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Latest commit

 

History

History
36 lines (31 loc) · 646 Bytes

README.md

File metadata and controls

36 lines (31 loc) · 646 Bytes

Component to parent events:

Sequence:

  1. Component's button @click...
  2. ...calls component’s addToCart method...
  3. ...which emits add-to-cart event...
  4. ...which triggers updateCart method in Vue instance

html:

<product @add-to-cart=“updateCart”></product>

component:

Vue.component(‘product’,{
    methods: {
        addToCart: function() {
            this.$emit(‘add-to-cart’)
        }
    },

    template: `
        <button @click=“addToCart”>Add to cart</button>
    `
}

Vue instance:

methods: {
    updateCart() {
        this.cart += 1;
    }
}