• vue全选与取消全选


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.js"></script>
    </head>
    <body>
    <div id="my">
     
    <input type="checkbox" :checked="all" @click="changeAll()"/> 全选
    <ul>
    <li v-for="(v,i) in items">
    <input type="checkbox" :checked="v.status" :index="i" @click="changeItems(i)"/> {{v.name}}
    </li>
    </ul>
    </div>
    <script>
    let vm = new Vue({
    el:"#my",
    data:{
    all:true,
    items:[
    {name:'手机',status:false},
    {name:'电脑',status:false},
    {name:'平板',status:true},
    {name:'包包',status:false}
    ],
    selectValue:[]
    },
    methods:{
    changeAll(){
    let self = this;
    this.all = !this.all
    this.items.forEach((val)=>{
    val.status = self.all
    })
    },
    changeItems(i){
    this.items[i].status = !this.items[i].status;
    let itemsStatus = this.items.every((val)=>{
    return val.status
    })
    console.log(itemsStatus)
    if(itemsStatus){
    this.all = true
    }else{
    this.all = false
    }
    }
    },
    mounted(){
    let itemsStatus = this.items.every((val)=>{
    return val.status
    })
    console.log(itemsStatus)
    if(itemsStatus){
    this.all = true
    }else{
    this.all = false
    }
    }
     
    })
    </script>
    </body>
    </html>
  • 相关阅读:
    java-正则表达式6
    java-正则表达式5
    java-正则表达式4
    java-正则表达式3
    java-正则表达式2
    12.5
    JAVA GUI随笔
    JAVA个人知识总结
    UML关系图
    JAVA中的聚集和组合的区别和联系
  • 原文地址:https://www.cnblogs.com/MDGE/p/10261264.html
Copyright © 2020-2023  润新知