分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

vue.js 组件监听

发布时间:2023-09-06 01:14责任编辑:顾先生关键词:js组件

一、在通过点击事件触发的子组件中:

addCart(event) { ?if (!event._constructed) { ???return; ?} ?if (!this.food.count) { ????Vue.set(this.food, ‘count‘, 1); ?} else { ?????this.food.count++; ?}this.$emit(‘cartadd‘, event.target)},// cartcontrol.vue组件

  

 二、在父组件中 

<div class="cartcontrol-wrapper"> ?<cartcontrol :food="food" v-on:cart-add="cartAdd"></cartcontrol></div>// goods.vue组件中使用v-on来监听<shopcart ref="shopcart" ????:selectFoods="selectFoods" ???:deliveryprice="seller.deliveryPrice" ??:minprice="seller.minPrice" ?></shopcart>methods:{ ?cartadd(target) { ????// 传递给子组件 ????this.$refs.shopcart.drop(target) ?}}

  

 三、在接收的子组件中

methods: { ???drop(el) { ???????console.log(el); ???}}// shopcart.vue组件

  

  

 

原文地址:http://coding.imooc.com/learn/questiondetail/3769.html

vue.js 组件监听

原文地址:http://www.cnblogs.com/karila/p/7601856.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved