当前位置:网站首页>【小程序】Vant-Weapp Radio单选框组件无法触发bind:Change事件
【小程序】Vant-Weapp Radio单选框组件无法触发bind:Change事件
2022-06-10 21:15:00 【micromicrofat】
基础库: 2.24.4
vant-weapp: 1.10.3
今天在用vant的时候发现一个bug:
与 Cell 组件一起使用时,点击Cell时能触发Click事件,但不能触发Change事件;仅在点击图标时能同时触发Click和Change事件,代码如下
<van-radio-group value="{
{ radio }}" bind:change="onChange">
<van-cell-group>
<van-cell title="单选框 1" clickable data-name="1" bind:click="onClick">
<van-radio slot="right-icon" name="1" />
</van-cell>
<van-cell title="单选框 2" clickable data-name="2" bind:click="onClick">
<van-radio slot="right-icon" name="2" />
</van-cell>
</van-cell-group>
</van-radio-group>
Page({
data: {
radio: '1',
},
onChange(event) {
console.log("onChange")
this.setData({
radio: event.detail,
});
},
onClick(event) {
const {
name } = event.currentTarget.dataset;
console.log("onClick", name)
this.setData({
radio: name,
});
},
});

解决办法就是在Click事件处理函数中实现Change事件处理函数, 代码如下
记得不要注册bind:change,不然会重复执行
<van-radio-group value="{
{ radio }}">
<van-cell-group>
<van-cell title="单选框 1" clickable data-name="1" bind:click="onClick">
<van-radio slot="right-icon" name="1" />
</van-cell>
<van-cell title="单选框 2" clickable data-name="2" bind:click="onClick">
<van-radio slot="right-icon" name="2" />
</van-cell>
</van-cell-group>
</van-radio-group>
Page({
data: {
radio: '1',
},
onChange(event) {
console.log("onChange")
this.setData({
radio: event.detail,
});
},
onClick(event) {
const {
name } = event.currentTarget.dataset;
console.log("onClick", name)
if (name !== this.data.radio) {
this.onChange(event);
}
this.setData({
radio: name,
});
},
});
边栏推荐
- 数组 从指定长度位旋转数组
- "The specified database user/password combination is rejected..." Solutions for
- 【phpstorm】 No data sources are configured to run this SQL and provide advanced c
- C语言-排序中的快速排序(简称快排)
- 系统重装以及查询系统性能
- Summary of common mysql8 commands in centos7 environment
- Install MySQL on Linux system. Problems encountered in xshell
- The system needs to scan all the files and try to identify the cover of the video
- C语言qsort()函数的使用(详解)
- AI blessing real-time interaction | analysis of zegoavatar facial expression following technology
猜你喜欢

Icml2022 | sharp maml: model independent meta learning for sharpness perception

《暗黑破坏神不朽》数据库资料站地址 暗黑不朽资料库网址

Differences between disk serial number, disk ID and volume serial number

Modify frontsortinglayer variable of spritemask

What are MySQL clustered indexes and nonclustered indexes?

很流行的状态管理库 MobX 是怎么回事?

修改SpriteMask 的 frontSortingLayer 变量
![[nk] Niuke monthly competition 51 f-average question](/img/b3/c36a0032e606f38fdc2f7c4562713c.png)
[nk] Niuke monthly competition 51 f-average question

Before we learn about high-performance computing, let's take a look at its history

【MySQL】表的约束
随机推荐
数组 两个数组的交集 II
Abbexa cell free DNA kit instructions
笔记(四)- 多线程
[nk] 牛客月賽51 G計算題
Shaping teenagers' comprehension ability with children's programming thinking
【Debug】could not find ref wiht poc XXX解决
Intelligent robot making progress in imitation learning
Apple zoom! It's done so well
2022 - 06 - 09 rk817 PMU Battery Temperature Detection
2022-06-09 rk817 PMU battery temperature detection
JVM runtime data area
String analysis and use
笔记(五)- JVM
ThinkPHP v6.0. X deserialization vulnerability recurrence
Apache相关的几个安全漏洞修复
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
Abbexa cdan1 siRNA instruction manual
Array move 0
Detailed explanation of MySQL range query optimization scenario instances
记录(二)
