小编给大家分享一下vue.js如何实现的全选与全不选功能,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
Vue是一套用于构建用户界面的渐进式JavaScript框架,Vue与其它大型框架的区别是,使用Vue可以自底向上逐层应用,其核心库只关注视图层,方便与第三方库和项目整合,且使用Vue可以采用单文件组件和Vue生态系统支持的库开发复杂的单页应用。
elementui是有checkbox组件,不过问题在于checkbox组件内只能嵌套简单的字符串,如果要嵌入标签怎么办?
首先渲染页面:
<el-checkbox v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox> <tbody v-for="item in orderData"> <tr> <td class="order-num" colspan="7"> <el-checkbox v-model="item.checkModel" @change="handleCheckItemChange" ></el-checkbox> <div class="num"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >订单号:{{item.orderNumber}}</a> <p>商户单号:{{item.shopNumber}}</p> </div> </td> <td class="order-action" colspan="2"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >查看详情</a>-<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >备注</a>-<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >加星</a> </td> </tr> <tr> <td> <div class="pic"> <img :src=item.orderPic alt=""> </div> <div class="info"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{item.name}}</a> <p>{{item.size}}</p> <p>商品来源:{{item.from}}</p> </div> </td> <td>{{item.number}}</td> <td>{{item.price}}</td> <td>-</td> <td>{{item.company}}</td> <td> <p>{{item.address}}</p> <p>({{item.phone}})</p> </td> <td>{{item.date}}<br />{{item.time}}</td> <td>{{item.state}}</td> <td>{{item.pay}}<br /><span v-if="item.postCost">(运费:{{item.postCost}})</span></td> </tr> </tbody>
初始化data数据:
checkAll:false, checkedAllShops:[], checkItemData:[], orderData:[ { checkModel:false, orderNumber:'2017081618322542542', shopNumber:'2017081618322542542', orderPic:'../../../../static/images/realtimeprofile01.png', name:'【商城】贴轻松穴位艾灸贴', size:'5贴*盒', from:'本店商品', number:'10', price:'200.00', company:'蒂花之秀', address:'童话镇', phone:'12345678910', date:'2018-1-12', time:'09:30:00', state:'订单关闭', pay:'400.00', postCost:'10' },{ checkModel:false, orderNumber:'2017081618322542542', shopNumber:'2017081618322542542', orderPic:'../../../../static/images/realtimeprofile01.png', name:'【商城】贴轻松穴位艾灸贴', size:'5贴*盒', from:'本店商品', number:'10', price:'200.00', company:'蒂花之秀', address:'童话镇', phone:'12345678910', date:'2018-1-12', time:'09:30:00', state:'订单关闭', pay:'400.00', postCost:'10.00' } ]
相关方法:
handleCheckAllChange(val){ this.orderData.map((item,i)=>{ item.checkModel = val; }) }, handleCheckItemChange(val){ for(let i = 0,l = this.orderData.length;i < l;i ++){ if(this.orderData[i].checkModel !== val){ this.checkAll = false; return; } } this.checkAll = val; }
看完了这篇文章,相信你对“vue.js如何实现的全选与全不选功能”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。