美文网首页Vue
计算属性的getter和setter

计算属性的getter和setter

作者: 程序员同行者 | 来源:发表于2018-07-12 18:35 被阅读0次
<!DOCTYPE html>
<html>
<head>
    <title>计算属性的getter和setter</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id='app'>
        {{fullName}}
    </div>

<script>
    var vm =  new Vue({
        el:'#app',
        data: {
            firstName: "Dell",
            lastName: "Dll"
        },
        computed: {
            fullName: {
                get: function() {
                    return this.firstName + " " + this.lastName;
                },
                set: function(vaule) {
                    var arr = vaule.split(" ");
                    this.firstName = arr[0];
                    this.lastName = arr[1];
                }
            }
        }
    })
</script>
</body>
</html>

相关文章

网友评论

    本文标题:计算属性的getter和setter

    本文链接:https://www.haomeiwen.com/subject/sswrpftx.html