微信小程序radio checked选中问题

在开发小程序的过程中遇到了radio选中之后,又变成未选中状态的问题,

 <view class="cell_view_layout">

                                <radio style="margin: 0;height: 60rpx;width:100rpx;transform: scale(0.7)" :value="index" :checked="index === courseIndex" />
                            </view>
  radioChange:function (evt) {
                console.log(evt)
                this.courseIndex = parseInt(evt.target.value);
               
            },

经过仔细研究,发现是通过元素的value传递过来的值是字符串,如果直接跟index(数字)比较会出现这个问题。找到原因之后,我们把方法改一下,把从元素中获取到的value转换成Int就可以了,如上图中的:

parseInt(evt.target.value)方法。

JS字符串转数字可以参考我的另一篇博客

JS字符串转数字

猜你喜欢

转载自blog.csdn.net/bitcser/article/details/103716591