微信小程序-带参数的组件事件绑定

问题

两个组件,相同的函数处理逻辑,处理对象不同,通过参数传递处理对象

解决

设置属性data-xx,然后通过event.target.dataset.phone获取,(currentTarget也可以)

<view bind:blur="checkPhone" data-phone="{
     
     {userPhone}}"></view>
<viewbind:blur="checkPhone" data-phone="{
   
   {reg_userPhone}}" ></view>
checkPhone: function (event) {
    
    
    console.log(event.target);
	console.log(event.target.dataset.phone);
}

https://img-blog.csdnimg.cn/20201019105915247.png#pic_center

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42100456/article/details/109156788