vue實現(xiàn)全選和反選功能
更新時間:2017年08月31日 14:54:44 作者:mystraight
這篇文章主要為大家詳細介紹了vue實現(xiàn)全選和反選功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)全選反選功能的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <script type="text/javascript" src = "vue.js"></script> <body> <div id = "test"> <input type='checkbox' v-model="checkBox.checked" class='input-checkbox' @click='checkedAll'>全選 <div v-for='checkb in checkboxData'> <input type='checkbox' class='input-checkbox' @click="checkItem" v-model='checkBox.items[checkb.id]'> {{checkb.value}} </div> </div> </body> <script> var vue = new Vue({ el:"#test", data:{ checkboxData:[ { id:'1', value:'蘋果' },{ id:'2', value:'荔枝' },{ id:'3', value:'香蕉' },{ id:'4', value:'火龍果' } ], checkBox:{ checked:false, items:{} } }, methods:{ checkedAll: function() { var _this = this; console.log(_this.checkboxData); console.log(this.checkBox.items); this.checkboxData.forEach(function (item) { console.log(item.id); _this.checkBox.items[item.id] = _this.checkBox.checked; console.log(_this.checkBox.items); }); //實現(xiàn)反選 }, checkItem:function(){ var unchecked = 0; var _this = this; this.checkboxData.forEach( function(item) { unchecked += (! _this.checkBox.items[item.id]) || 0; }); _this.checkBox.checked = unchecked > 0 ? false : true; } } }) </script> </html>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用vant-picker實現(xiàn)自定義內(nèi)容,根據(jù)內(nèi)容添加圖標
這篇文章主要介紹了使用vant-picker實現(xiàn)自定義內(nèi)容,根據(jù)內(nèi)容添加圖標,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12在vue中路由使用this.$router.go(-1)返回兩次問題
這篇文章主要介紹了在vue中路由使用this.$router.go(-1)返回兩次問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12使用Vue Router進行路由組件傳參的實現(xiàn)方式
Vue Router 為 Vue.js 應用提供了完整的路由解決方案,其中包括了組件間的數(shù)據(jù)傳遞功能,通過路由組件傳參,我們可以輕松地在導航到新頁面時傳遞必要的數(shù)據(jù),本文將深入探討如何使用 Vue Router 進行路由組件間的傳參,并通過多個示例來展示其實現(xiàn)方式2024-09-09