vue 模块通信

来源:互联网 发布:mac os 11.12 cdr 编辑:程序博客网 时间:2024/06/14 03:43

1.cart-control子控件传值-----> 父控件

 methods: {    addCart(event) {      console.log(event.target);      if (!event._constructed) {        return      }      if (!this.food.count) {        Vue.set(this.food, 'count', 0)      }      this.food.count++;      //cart.add事件监听  event.targetDom事件传递      //this.$root.eventHub.$emit('cart.add', event.target)      this.$dispatch('cart.add',event.target);   }}

2.goods父控件

<template>     <shopcart v-ref:shopcart></shopcart></template>
//接受子控件传过来的事件events: {   'cart.add'(target) {   this._drop(target);}}
methods: {    //父控件可以调用子控件的方法    _drop(target){    this.$ref.shopcart.drop(target);}  
3.shopcart子控件
//父控件传到子控件methods: {    drop: (el){    consule.log(el);}}


原创粉丝点击