VUE2 uniapp 父子组件事件传递

本文详细阐述了在Vue应用中,如何通过子组件的
摘要由CSDN通过智能技术生成

子组件事件传递给父组件

  • 父组件
<template>
....
<diyItemAdd   @delDiyItemCall="delDiyItem" :itemInfo="item" v-for="(item,index) in jl_content_form.diyItem" :key="item.itemID"></diyItemAdd>
...
<template>
<script>
methods: {
			delDiyItem(e){
				console.log(e)
				// debugger

			},
</script>

html中,需要给子组件的属性中注册一个事件@delDiyItemCall="delDiyItem",用于子组件触发
这里delDiyItem是父组件的方法,子组件在触发事件的时候,会调用父组件的这个方法
@delDiyItemCall这个是给子组件注册事件的作用

  • 子组件(diyItemAdd)
<template> 
	<view >	  		 
		<button class="cu-btn bg-blue light" size="mini" @click="del" >删除</button>
	</view>
</template>
<script>
methods:{
			del(){
				this.$emit("delDiyItemCall",this.itemInfo.itemID)
			}
		}
</script>

子组件中 @click 是子组件button的点击事件。这里指向了子组件的del()方法
在del()方法中,通过 this.$emit("父组件引用时,注册的事件名字","相关参数") 来触发父组件的注册事件。
上面的子组件通过按钮button 点击后,执行了父组件的delDiyItem()方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

何浩翔

如果对你多帮助,请支持。感谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值