vue.js self-study (D4)

Self vue.js (D1)

Binding of array syntax style

04 Computed Property

01 using basic (P20) of calculating an attribute

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h2>{{message}}</h2>
        <!--最原始方法-->
        <h2>{{firstName}} {{lastName}}</h2>
        <!--通过方法-->
        <h2>{{getFullName()}}</h2>
        <!--计算属性,不需要加小括号-->
        <h2>{{fullName}}</h2>

    </div>
    <script src="../js/vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                message:'你好啊',
                firstName: 'Lebron',
                lastName: 'James'
            },
            methods: {
                getFullName(){
                    return this.firstName + ' ' + this.lastName
                }
            },
            computed: {
                fullName: function(){
                    return this.firstName + ' ' + this.lastName
                }
            }
        })
    </script>
</body>
</html>
Published 22 original articles · won praise 1 · views 538

Guess you like

Origin blog.csdn.net/fangpihuiyu/article/details/104370411