码迷,mamicode.com
首页 > 其他好文 > 详细

Vue v-for操作与computed结合功能

时间:2019-10-06 16:55:52      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:https   http   har   style   写法   标签   body   user   class   

<!doctype html>
<html lang="en">
<head id="head">
    <meta charset="UTF-8">
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
    <title>{{title}}</title>
</head>
<body>
<div id="ask"><!--vue不能控制body和html的标签-->
     <li v-for="v in stus">
        {{v.name}} ======> {{v.sex}}
     </li>
    <input type="radio" v-model="type" value="all" checked> 全部
    <input type="radio" v-model="type" value="boy" > 男孩
    <input type="radio" v-model="type" value="girl" > 女孩
</div>
<script>
    var vue = function (options){new Vue(options)};
    vue({
        el:#head,
        data:{
            title:Vue v-for操作与computed结合功能
        }
    });
    var app = vue({
        //element
        el:#ask,
        computed:{
            stus(){
                if(this.type == all){
                    return this.user;
                }else{
                    /*es6写法 防止用不了this.type*/
                    return this.user.filter((v)=>{
                        return v.sex == this.type;
                    })
                }
            }
        },
        data:{
            type:all,
            user:[
                {name:小刘,sex:boy},
                {name:小王,sex:boy},
                {name:小花,sex:girl},
                {name:小芳,sex:girl},
            ]
        }
    });

</script>
</body>
</html>

 

Vue v-for操作与computed结合功能

标签:https   http   har   style   写法   标签   body   user   class   

原文地址:https://www.cnblogs.com/tommymarc/p/11627502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!