<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/vant@2.12/lib/index.css"
/>
<!-- 引入组件 -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vant@2.12/lib/vant.min.js"></script>
</head>
<body>
<div id="app">
<van-checkbox-group v-model="checked" ref="checkboxGroup" @change="onChangeGroup">
<template v-for="item in list">
<div :key="item.id" class="item">
<van-checkbox :name="item" @click="fff()"/>
<div class="content" :style="{width: clientWidth-46+‘px‘}">
<div>{{item.name}}</div>
<div>{{item.tel}}</div>
<div>{{item.address}}</div>
</div>
</div>
</template>
</van-checkbox-group>
<button @click="onAll()">全选</button>
</div>
</body>
<script>
var app = new Vue({
el: ‘#app‘,
data() {
return {
clientWidth: 0,
isEdit: false,
checked: [],
list: [
{
id: "1",
name: "张三",
tel: "13000000000",
address: "浙江省杭州市西湖区文三路",
},
{
id: "2",
name: "李四",
tel: "1310000000",
address: "浙江省杭州市拱墅区莫干山路"
}
],
}
},
mounted(){
this.clientWidth = document.body.clientWidth;
},
methods:{
//官网API上的change方法
onChangeGroup(event){
console.log(event,‘change‘);
},
onAll(item) {
//没有全选,点击是全选,全选的情况下,点击时全不选
this.$refs.checkboxGroup.toggleAll();
},
//官网API上的click方法
fff(){
console.log(this.checked,‘click‘);
}
}
})
Vue.use(vant.ActionSheet,vant.List,vant.AddressList);
</script>
<style scoped>
.wrapp {
padding: 0 10px;
}
.item {
white-space: nowrap;
margin-top: 10px;
overflow: hidden;
}
.check {
padding: 0 10px;
width: 40px;
display: inline-block;
position: relative;
top: -30px;
}
.content {
display: inline-block;
padding: 12px;
background-color: #fff;
border-radius: 8px;
white-space: normal;
}
</style>
</html>
原文:https://www.cnblogs.com/youzi555/p/14518176.html