vue understanding of the computed and wherein computing properties get, set of

After re-learn vue, learned this calculation property, to understand a little bit, but they can not think of what to use when

Calculation ------------ ------------ attributes are cached based on their responses dependent formula

get is based on other data to get to the data computed in the definition of

It is set to change other data computed based on the data defined in

It being understood that, to understand the new changes, the following to cases, on the whole election

<html>
<head>
<title>vue5 全选</title>
</head>
<style>
    
</style>

<body>
    <div id="app">
        <ul>
            <li ><span><input type="checkbox" v-model="allcheck"/></span>全选</li><br/>
            <li v-for="item in datalist"><span><input type="checkbox" v-model="item.status"/></span>{{item.xueli}}</li><br/>
            

        </ul>
        <input type="button" value="批量操作" />
    </div>
        
</body>
<script src="vue.js"></script>
<script src="axios.min.js"></script> 


< Script > 
    var DataList = [ 
    {ID: . 1 , Xueli: ' Primary ' , Status: to false }, 
    {ID: 2 , Xueli: ' Junior ' , Status: to false }, 
    {ID: . 3 , Xueli: ' School ' , Status: to false }, 
    {ID: . 4 , Xueli: ' University ' , Status: to true } 
    ]; 
    var VM = new new Vue ({ 
        EL: "#app",
        data:{        
            
              datalist:datalist
           
        },
        computed:{
            allcheck:{
            get:function(){
            var newarr=[];
            newarr=this.datalist.filter(function(item){
            return !item.status;
            });
            if(newarr.length==0){
            return true;
            }
            },
            set:function(value){
            this.datalist.forEach(function(item){item.status=value});
            }
            }
        }
        
    });
</script>
</html>

 

Guess you like

Origin www.cnblogs.com/jcydd/p/11431787.html