您好,登錄后才能下訂單哦!
小編給大家分享一下vue.js如何實(shí)現(xiàn)的全選與全不選功能,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
Vue是一套用于構(gòu)建用戶界面的漸進(jìn)式JavaScript框架,Vue與其它大型框架的區(qū)別是,使用Vue可以自底向上逐層應(yīng)用,其核心庫(kù)只關(guān)注視圖層,方便與第三方庫(kù)和項(xiàng)目整合,且使用Vue可以采用單文件組件和Vue生態(tài)系統(tǒng)支持的庫(kù)開(kāi)發(fā)復(fù)雜的單頁(yè)應(yīng)用。
elementui是有checkbox組件,不過(guò)問(wèn)題在于checkbox組件內(nèi)只能嵌套簡(jiǎn)單的字符串,如果要嵌入標(biāo)簽怎么辦?
首先渲染頁(yè)面:
<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" >訂單號(hào):{{item.orderNumber}}</a> <p>商戶單號(hào):{{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>商品來(lái)源:{{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">(運(yùn)費(fèi):{{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; }
看完了這篇文章,相信你對(duì)“vue.js如何實(shí)現(xiàn)的全選與全不選功能”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。