其他分享
首页 > 其他分享> > VUE计算属性

VUE计算属性

作者:互联网

在这里插入图片描述 computed:注重结果
1.逻辑计算,防止模板过重
2.监听:依赖修改 。get方法必须return

<!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="box">
        {{mycomputedname}}
        <hr>
        <input type="text" v-model="mytext" name="" id="">
        {{mydatalist}}
        <ul>
            <li v-for="data in mydatalist">
                {{data}}
            </li>
        </ul>
    </div>
    <script>
        new Vue({
            el:'#box',
            data:{
                myname:'kerwin',
                mytext:'',
                datalist:["aaa",'sdsd','sdsfs','sdfdsfds']
            },
            computed:{
                mycomputedname(){
                    return this.myname.substring(0,1).toUpperCase()+this.myname.substring(1)
                },
                mydatalist(){
                    return this.datalist.filter(item=>item.includes(this.mytext))
                }
            }
        })
    </script>
</body>
</html>

标签:VUE,return,computed,datalist,myname,item,计算,mydatalist,属性
来源: https://blog.csdn.net/weixin_43778556/article/details/116881768