为啥动态显示的名字就显示了undefined?

  看不懂了昂,记录一下,慢慢理解吧

<!DOCTYPE html> 
<html> 
<head> <meta charset="utf-8">
    <title>Vue 示例</title>
</head> 
<body>
    <div id="app" >
       姓名:{{ fullName }}
    </div>
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script>
    var padDate = function(value){
        return value < 10 ? '0' + value :value;
    }
    var app = new Vue({
        el: '#app',
        data: {
            fistName: 'Jack',
            lastName: 'Green'
        },
       
       computed: {
           fullName: {
               // Getter, 用于读取
               get: function () {
                   return this.fistName + ',' + this.lastName;
               },
               // Setter,写入时触发
               set: function (newValue) {
                    var names = newValue.split(',');
                    this.fistName = names[0];
                    this.lastName = names[names.length - 1];
               }
           }
       } 
    })
</script>
</body>
</html>

  

posted on 2020-09-18 13:52  王半仙儿的博客  阅读(326)  评论(0编辑  收藏  举报

导航