短视频,自媒体,达人种草一站处事
这篇文章首要为各人具体先容了vue行使vant中的checkbox实现全选成果,文中示例代码先容的很是具体,具有必然的参考代价,感乐趣的小搭档们可以参考一下
本文实例为各人分享了vue行使vant中的checkbox实现全选成果的详细代码,供各人参考,详细内容如下
<template> <div> <topbar /> <ul> <li v-for="(item, index) in people" :key="index"> <van-checkbox v-model="item.flag"
></van-checkbox> <div> <p>{{ item.name }}</p> <p>{{ item.id }}</p> </div> </li> </ul> <div> <div> <van-checkbox v-model="allcheck">全选</van-checkbox> </div> <button @click="jump">确定</button> </div> </div> </template> <script> export default { data() { return { people: [ { id: "002", name: "陈阳", flag: true }, { id: "003", name: "王苗苗", flag: true, }, { id: "004", name: "张梁俊", flag: true, }, { id: "005", name: "刘路", flag: true, }, ], }; }, methods: { //点击确定后跳转回新增条约页面 jump() { this.$router.push("/addContract"); }, //单选按钮切换 // change(index) { // this.people[index].flag = !this.people[index].flag; // console.log(this.people[index].flag); // }, }, computed:{ allcheck:{ get(){ //取值 //every要领,数组中每一项都满意一个前提返回true return this.people.every(item=>item.flag) }, set(newValue){ //配置值 console.log('触发set要领') this.people.map(item=>item.flag=newValue) } }, filterAll(){ return this.people.filter(item=>item.flag).length }, count(){ let checkedList=this.people.filter(item=>item.flag) return checkedList.length.reduce((total,item)=>{ return total+item.num },0) } } }; </script> <style lang="less" scoped> .list { background: #f8f9fb; height: 574px; li { height: 56px; margin: 10px 0 10px 0; float: left; img { width: 19px; height: 19px; float: left; margin: 13px; &.on { display: block; } &.off { display: none; } } .listli { float: left; margin: 19px 13px 0 13px; } .right { float: left; background: #ffffff; width: 328px; height: 56px; padding: 0px 0 0 13px; box-sizing: border-box; p:nth-of-type(1) { font-size: 15px; font-family: PingFang SC; font-weight: 400; color: #000000; line-height: 29px; } p:nth-of-type(2) { font-size: 13px; font-family: PingFang SC; font-weight: 400; color: #666666; line-height: 14px; } } } } .bottom { height: 50px; position: fixed; bottom: 0; .left { width: 237px; background: #ffffff; height: 100%; float: left; img { width: 18px; float: left; margin: 18px 13px 0 18px; &.on { display: block; } &.off { display: none; } } .all { margin: 17px 0 0 14px; } p { float: left; font-size: 13px; font-family: PingFang SC; font-weight: 400; color: #333333; margin-top: 18px; } } button { float: left; width: 138px; height: 50px; line-height: 50px; background: #336afa; color: #ffffff; } } </style>
本次碰着的题目是本身一开始没发此刻people数组内里,界说的每一项flag的值配置的范例为字符串型即flag="true",导致一开始进入页面所有无论值为true照旧false,复选框都是选中结果,修改之后便没有了此题目。
关于vue.js组件的教程,请各人点击专题vue.js组件进修教程举办进修。
更多vue进修教程请阅读专题《vue拭魅战教程》 (编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|