Vue.js 实现全选功能:复选框全选与全选自动选中
<!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>
<script src='vue.js'></script>
</head>
<body>
<div id='app'>
全选:<input type='checkbox' v-model='selectAll' @change='selectAllBoxes'>
<input type='checkbox' v-model='box1'>
<input type='checkbox' v-model='box2'>
<input type='checkbox' v-model='box3'>
</div>
<script>
new Vue({
el:'#app',
data:{
selectAll:false,
box1:false,
box2:false,
box3:false
},
methods:{
selectAllBoxes(){
this.box1 = this.selectAll;
this.box2 = this.selectAll;
this.box3 = this.selectAll;
}
}
})
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/nzOc 著作权归作者所有。请勿转载和采集!