<div style="display: inline-block">
<span>自定义月份:</span>
<span v-for="(item,index) in months">
<input type="checkbox" :checked="customMonths.indexOf(item)>=0" @click="customMonthChecked(item)" name="custom_months" :value="item"> <span>{{item}}</span>
</span>
</div>
数据部分
data:{
months:["01","02","03","04","05","06","07","08","09","10","11","12"],
customMonths:[],
},
方法部分
methods:{
customMonthChecked(mon){
let index = this.customMonths.indexOf(mon)
if(index>=0){
// 如果已经包含了该元素, 则去除
this.customMonths.splice(index,1)
}else{
this.customMonths.push(mon)
}
},
}
本示例中的数据部分是数组元数据,当然也可以是Model,使用的时候可以根据情况适当修改
暂无评论
要发表评论,您必须先 登录