小編給大家分享一下vue.js如何實現(xiàn)的全選與全不選功能,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
Vue是一套用于構(gòu)建用戶界面的漸進式JavaScript框架,Vue與其它大型框架的區(qū)別是,使用Vue可以自底向上逐層應用,其核心庫只關(guān)注視圖層,方便與第三方庫和項目整合,且使用Vue可以采用單文件組件和Vue生態(tài)系統(tǒng)支持的庫開發(fā)復雜的單頁應用。
elementui是有checkbox組件,不過問題在于checkbox組件內(nèi)只能嵌套簡單的字符串,如果要嵌入標簽怎么辦?
首先渲染頁面:
<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數(shù)據(jù):
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:'童話鎮(zhèn)', phone:'12345678910', date:'2018-1-12', time:'09:30:00', state:'訂單關(guān)閉', 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:'童話鎮(zhèn)', phone:'12345678910', date:'2018-1-12', time:'09:30:00', state:'訂單關(guān)閉', pay:'400.00', postCost:'10.00' } ]
相關(guān)方法:
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如何實現(xiàn)的全選與全不選功能”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設計公司行業(yè)資訊頻道,感謝各位的閱讀!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
當前名稱:vue.js如何實現(xiàn)的全選與全不選功能-創(chuàng)新互聯(lián)
鏈接分享:http://aaarwkj.com/article16/coidgg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供云服務器、自適應網(wǎng)站、品牌網(wǎng)站建設、外貿(mào)建站、服務器托管、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容