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

simonl65/vm-01-intro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
    }
}

About

Vue Mastery: Intro to Vue.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published