首页 > 其他 > 详细

vue---computed

时间:2019-04-14 19:51:43      阅读:107      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>

</head>
<body>
    <div id = "app">
        姓:<input type="text" v-model="firstName">
        名:<input type="text" v-model="lastName">
        <p>{{name()}} 这是methods方法</p>
        <p>{{fullname}} 这是computed</p>
    </div>
    <script>
        let vm = new Vue({
            el:"#app",
            data:{
                firstName:"",
                lastName:""
            },
            methods:{
                name(){
                    return this.firstName +this.lastName
                }
            },
            computed:{
                fullname:{
                    get:function(){
                        return this.firstName + this.lastName
                    },
                }
            }
        })
    </script>
</body>
</html>

  

vue---computed

原文:https://www.cnblogs.com/mengtong/p/10706577.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!