vue는 vant의 checkbox를 사용하여 전체 선택 기능을 실현합니다
<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: " ", flag: true },
{
id: "003",
name: " ",
flag: true,
},
{
id: "004",
name: " ",
flag: true,
},
{
id: "005",
name: " ",
flag: true,
},
],
};
},
methods: {
//
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 , true
return this.people.every(item=>item.flag)
},
set(newValue){
//
console.log(' 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>
이번 문제는 처음에people 그룹에서 정의된 모든 flag의 값 설정 형식이 문자열형인 flag="true"라는 것을 발견하지 못했기 때문에 처음에 페이지에 들어가면 모든 값이true든false이든 복선상자가 선택된 효과입니다. 수정하면 이 문제가 없습니다.vue에 관하여.js 구성 요소의 강좌입니다. 테마를 클릭하십시오vue.js 구성 요소 학습 강좌 공부를 합니다.
더 많은 vue 학습 강좌는 주제를 읽어 주십시오《vue 실전 강좌》.
이상은 본문의 전체 내용입니다. 여러분의 학습에 도움이 되고 저희를 많이 응원해 주십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fastapi websocket 및 vue 3(Composition API)1부: FastAPI virtualenv 만들기(선택 사항) FastAPI 및 필요한 모든 것을 다음과 같이 설치하십시오. 생성main.py 파일 및 실행 - 브라우저에서 이 링크 열기http://127.0.0.1:...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.