vue v-for如何让checkbox 选中的时候,当前index加个class,如下图和代码

想要的效果

https://img4.mukewang.com/5c8f511c0001049404740270.jpg

现在的问题

https://img.mukewang.com/5c8f511d00016dcb05490323.jpg

https://img4.mukewang.com/5c8f511e0001612505580369.jpg

代码

                            <li v-for="(item,index) in tableTitleTable" :class="{'actived':itemTexAtctived}" class="body-item">
                                <label class="checkbox">
                                    <input v-model="itemTexAtctived" type="checkbox"/>
                                    <span></span>
                                </label>
                                <span class="item-text">{{item}}</span>
                            </li>
      itemTexAtctived: false,
      tableTitleTable:["ID","讲义标题","所属教材","年级","科目","使用次数","来源","创建人","创建时间"]
函数式编程
浏览 1533回答 3
3回答

小唯快跑啊

tableTitleTable:[{item:"ID",isChecked:false},{item:"讲义标题",isChecked:false},{item:"所属教材",isChecked:false},{item:"年级",isChecked:false},{item:"科目",isChecked:false},{item:"使用次数",isChecked:false},{item:"来源",isChecked:false},{item:"创建人",isChecked:false},{item:"创建时间",isChecked:false}] <li v-for="(item,index) in tableTitleTable" :class="{'actived':item.isChecked}"<input v-model="itemTexAtctived" type="checkbox" @click="changeChecked(index)"/> changeChecked(index) { this.tableTitleTable[index].isChecked = !this.tableTitleTable[index].isChecked}机房电脑没有编译器,记事本敲得。可能有点错误,大概思想就是这样。数据里增加一个isChecked状态,通过改变这个状态来改变样式。

倚天杖

做个判断就好了 <input v-model="itemTexAtctived" type="checkbox" checked={{index === curIndex}}/>
打开App,查看更多内容
随时随地看视频慕课网APP