vue.js實(shí)現(xiàn)的全選與全不選功能示例【基于elementui】
本文實(shí)例講述了vue.js實(shí)現(xiàn)的全選與全不選功能。分享給大家供大家參考,具體如下:
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" style="vertical-align:top;margin-top:20px;"></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ù)單號(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:'童話(huà)鎮(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:'童話(huà)鎮(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;
}
css代碼就不貼出來(lái)了,不好看,哈哈
感興趣的朋友還可以使用本站如下在線工具測(cè)試運(yùn)行效果:
在線HTML/CSS/JavaScript前端代碼調(diào)試運(yùn)行工具:
http://tools.jb51.net/code/WebCodeRun
在線HTML/CSS/JavaScript代碼運(yùn)行工具:
http://tools.jb51.net/code/HtmlJsRun
希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。
相關(guān)文章
nuxt 自定義 auth 中間件實(shí)現(xiàn)令牌的持久化操作
這篇文章主要介紹了nuxt 自定義 auth 中間件實(shí)現(xiàn)令牌的持久化操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
Vue標(biāo)簽屬性動(dòng)態(tài)傳參并拼接字符串的操作方法
這篇文章主要介紹了Vue標(biāo)簽屬性動(dòng)態(tài)傳參并拼接字符串的操作方法,我們需要根據(jù)傳入值的類(lèi)型,在placeholder屬性賦值"請(qǐng)輸入長(zhǎng)度",“請(qǐng)輸入寬度”,"請(qǐng)輸入厚度"等提示字符,本文通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧2023-11-11
vue項(xiàng)目npm install失敗的問(wèn)題解決方案
本文主要介紹了vue項(xiàng)目npm install失敗的問(wèn)題解決方案,文中通過(guò)圖文示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-01-01
Vue.js中該如何自己維護(hù)路由跳轉(zhuǎn)記錄
這篇文章主要給大家介紹了關(guān)于Vue.js中該如何自己維護(hù)路由跳轉(zhuǎn)記錄的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Vue.js具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
使用vue-touch報(bào)priority錯(cuò)誤的解決
這篇文章主要介紹了使用vue-touch報(bào)priority錯(cuò)誤的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
vue-cropper組件實(shí)現(xiàn)圖片切割上傳
這篇文章主要為大家詳細(xì)介紹了vue-cropper組件實(shí)現(xiàn)圖片切割上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05

