vue学习(七) 计算属性的getter和setter方法

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="../vue/vue.js"></script>
    <title>学习vue</title>
</head>

<body>
    <div id="app">
        <div>{{fullName}}</div>
    </div>

    <script>
        var app = new Vue({
            el: '#app',
            data: {
                firstName: 'zhou',
                lastName: 'jin',
            },
            computed: {
                fullName: {
                    //getter
                    get: function() {
                        return this.firstName + ' ' + this.lastName
                    },
                    //setter
                    set: function(value) {
                        var arr = value.split(" ");
                        this.firstName = arr[0];
                        this.lastName = arr[1];
                    }
                }
            }
        })
    </script>
</body>

</html>
上一篇:合理利用Java不可变对象,让你的代码更加优雅


下一篇:java后台调用前端js方法传值问题