Wednesday, May 2, 2018

Vuejs $emit('close') and v-on

use component -> template @click="$emit('close')

on parent

explain in
https://laracasts.com/series/learn-vue-2-step-by-step/episodes/10?autoplay=true


communicate between parent and children components.

v-on: or @on:coupon_applied="onCouponApplied"
applied is event such as click, blur and so on
onCouponApplied is method or function name
onCouponApplied(dataName) {
  ....
}

this dataName is from children $emit passed dataName.

this method will create the method on the parent or root component.

on the children components
template: ''

in the children methods:
methods: {
  onCouponApplied() {
    this.$emit('coupon_applied', dataName)
  }
}

the dataName is object or array or some data want to send to parent.
$emit: the applied is parent event name. such as coupon_applied


No comments: