Alex Vincent's Blog

Alex's Blog
Where he writes his thoughts and experiences.
  1. 首页
  2. 默认分类
  3. 正文

Vue坑位记录 (01): iCheck模拟v-model

12月 23, 2018 5546点热度 11人点赞 0条评论

一、坑的形状

iCheck自带 ifChecked/ifUnchecked 事件,但实际在选中相关CheckBox和Radio时,原有<input>没有进行更新,选中状态绑定在了iCheck实例上。这时通过v-model绑定时,无法触发监听handler。

二、填坑材料

iCheck事件、iCheck target、vm实例、v-model对象。

三、填坑过程

在初始化iCheck实例时,同时绑定ifCheck事件:

mounted () {
    const $vm = this
    $('.checkboxes input').each(function () {
        const self = $(this)
        self
            .iCheck({ /** Some options... **/ })
            .on('ifChecked', function (event) {
                $vm.someData[event.target.getAttribute('name')] = parseInt($(event.target).val())
            })
        })
    }
}

标签: 暂无
最后更新:12月 23, 2018

Alex Li

He's less to speak.

点赞
< 上一篇
下一篇 >

COPYRIGHT © 2023 Alex Li. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

桂ICP备16008143号-1