您好,登錄后才能下訂單哦!
小編給大家分享一下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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。