zoukankan      html  css  js  c++  java
  • vue基础04计算属性

    00.计算属性

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script src="../js/vue.js"></script>
    </head>
    <body>
    
        <div id="app">
            <!-- 一般情况下写法:这种每次都会计算,效率低 -->
            <h1>{{firstname+lastname}}</h1>
            <!-- 计算属性 -->
            <h1>{{fullname}}</h1>
        </div>
        <script type="text/javascript">
            var app=new Vue({
                el:"#app",
                data:{
                    firstname:"",
                    lastname:""
                },
                computed:{//计算属性
                    fullname:function(){
                        return this.firstname+this.lastname
                    }
                }
            })
        </script>
    </body>
    </html>

    01.列表渲染和计算属性混合使用

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script src="../js/vue.js"></script>
    </head>
    <body>
    
        <div id="app">
            <!-- 一般情况下写法:这种每次都会计算,效率低 -->
            <h1>{{firstname+lastname}}</h1>
            <!-- 计算属性 -->
            <h1>{{fullname}}</h1>
        </div>
        <script type="text/javascript">
            var app=new Vue({
                el:"#app",
                data:{
                    firstname:"",
                    lastname:""
                },
                computed:{//计算属性
                    fullname:function(){
                        return this.firstname+this.lastname
                    }
                }
            })
        </script>
    </body>
    </html>
  • 相关阅读:
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    MFC/.NET
    学习小结——记于华为2018届校园招聘宣讲会之后
    槽点今天未想到
  • 原文地址:https://www.cnblogs.com/hunter1/p/15250767.html
Copyright © 2011-2022 走看看