vue使用vant中的checkbox實(shí)現(xiàn)全選功能
本文實(shí)例為大家分享了vue使用vant中的checkbox實(shí)現(xiàn)全選功能的具體代碼,供大家參考,具體內(nèi)容如下
<template>
<div class="visiblePeople">
<topbar />
<ul class="list clear_float">
<li v-for="(item, index) in people" :key="index">
<van-checkbox
v-model="item.flag"
class="listli"
></van-checkbox>
<div class="right">
<p>{{ item.name }}</p>
<p>{{ item.id }}</p>
</div>
</li>
</ul>
<div class="bottom">
<div class="left">
<van-checkbox v-model="allcheck" class="all">全選</van-checkbox>
</div>
<button @click="jump">確定</button>
</div>
</div>
</template>
<script>
export default {
data() {
return {
people: [
{ id: "002", name: "陳陽(yáng)", flag: true },
{
id: "003",
name: "王苗苗",
flag: true,
},
{
id: "004",
name: "張梁俊",
flag: true,
},
{
id: "005",
name: "劉路",
flag: true,
},
],
};
},
methods: {
//點(diǎn)擊確定后跳轉(zhuǎn)回新增合同頁(yè)面
jump() {
this.$router.push("/addContract");
},
//單選按鈕切換
// change(index) {
// this.people[index].flag = !this.people[index].flag;
// console.log(this.people[index].flag);
// },
},
computed:{
allcheck:{
get(){
//取值
//every方法,數(shù)組中每一項(xiàng)都滿足一個(gè)條件返回true
return this.people.every(item=>item.flag)
},
set(newValue){
//設(shè)置值
console.log('觸發(fā)set方法')
this.people.map(item=>item.flag=newValue)
}
},
filterAll(){
return this.people.filter(item=>item.flag).length
},
count(){
let checkedList=this.people.filter(item=>item.flag)
return checkedList.length.reduce((total,item)=>{
return total+item.num
},0)
}
}
};
</script>
<style lang="less" scoped>
.list {
background: #f8f9fb;
height: 574px;
li {
height: 56px;
margin: 10px 0 10px 0;
float: left;
img {
width: 19px;
height: 19px;
float: left;
margin: 13px;
&.on {
display: block;
}
&.off {
display: none;
}
}
.listli {
float: left;
margin: 19px 13px 0 13px;
}
.right {
float: left;
background: #ffffff;
width: 328px;
height: 56px;
padding: 0px 0 0 13px;
box-sizing: border-box;
p:nth-of-type(1) {
font-size: 15px;
font-family: PingFang SC;
font-weight: 400;
color: #000000;
line-height: 29px;
}
p:nth-of-type(2) {
font-size: 13px;
font-family: PingFang SC;
font-weight: 400;
color: #666666;
line-height: 14px;
}
}
}
}
.bottom {
height: 50px;
position: fixed;
bottom: 0;
.left {
width: 237px;
background: #ffffff;
height: 100%;
float: left;
img {
width: 18px;
float: left;
margin: 18px 13px 0 18px;
&.on {
display: block;
}
&.off {
display: none;
}
}
.all {
margin: 17px 0 0 14px;
}
p {
float: left;
font-size: 13px;
font-family: PingFang SC;
font-weight: 400;
color: #333333;
margin-top: 18px;
}
}
button {
float: left;
width: 138px;
height: 50px;
line-height: 50px;
background: #336afa;
color: #ffffff;
}
}
</style>
本次遇到的問(wèn)題是自己一開(kāi)始沒(méi)發(fā)現(xiàn)在people數(shù)組里面,定義的每一項(xiàng)flag的值設(shè)置的類型為字符串型即flag="true",導(dǎo)致一開(kāi)始進(jìn)入頁(yè)面全部無(wú)論值為true還是false,復(fù)選框都是選中效果,修改之后便沒(méi)有了此問(wèn)題。
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請(qǐng)閱讀專題《vue實(shí)戰(zhàn)教程》
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決vue項(xiàng)目F5刷新mounted里的函數(shù)不執(zhí)行問(wèn)題
今天小編就為大家分享一篇解決vue項(xiàng)目F5刷新mounted里的函數(shù)不執(zhí)行問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11
解決使用vue-awesome-swiper組件手動(dòng)滾動(dòng)點(diǎn)擊失效問(wèn)題
這篇文章主要介紹了使用vue-awesome-swiper組件手動(dòng)滾動(dòng)點(diǎn)擊失效問(wèn)題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
解決Vue 給mapState中定義的屬性賦值報(bào)錯(cuò)的問(wèn)題
這篇文章主要介紹了解決Vue 給mapState中定義的屬性賦值報(bào)錯(cuò)的問(wèn)題,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06
Vue極簡(jiǎn)生成器?Vuepress的實(shí)現(xiàn)
本文主要介紹了Vue極簡(jiǎn)生成器?Vuepress的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧<BR>2022-06-06
Vue自定義指令中無(wú)法獲取this的問(wèn)題及解決
這篇文章主要介紹了Vue自定義指令中無(wú)法獲取this的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
vue增加強(qiáng)緩存和版本號(hào)的實(shí)現(xiàn)方法
這篇文章主要介紹了vue增加強(qiáng)緩存和版本號(hào)的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
Vue.js watch監(jiān)視屬性知識(shí)點(diǎn)總結(jié)
在本篇文章里小編給大家分享的是關(guān)于Vue.js watch監(jiān)視屬性的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。2019-11-11
vue全局引入公共的scss和@mixin與@include的使用方式
這篇文章主要介紹了vue全局引入公共的scss和@mixin與@include的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02
vue 登錄滑動(dòng)驗(yàn)證實(shí)現(xiàn)代碼
這篇文章主要介紹了vue 登錄滑動(dòng)驗(yàn)證實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08
vue內(nèi)置組件keep-alive事件動(dòng)態(tài)緩存實(shí)例
這篇文章主要介紹了vue內(nèi)置組件keep-alive事件動(dòng)態(tài)緩存實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10

