zoukankan      html  css  js  c++  java
  • 09 计算属性之computed

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <!--    computed:对于比较长的计算和代码,放入computed方法中,直接{{函数名}}调用 同时监听数据变化作用-->
        <div id="app">
            {{reverseMsg}}
            <h3>{{fullName}}</h3>
            <button @click="handleClick">改变</button>
        </div>
        <script src="vue.js"></script>
        <script>
            new Vue({
                el:'#app',
                data:{
                    msg:'hello',
                    firstName:'walter',
                    lastName:'lizzy'
                },
                methods:{
                  handleClick:function () {
                        this.msg = '计算属性computed'
                  }
                },
                computed:{
                    //computed默认只有getter方法
                    //计算属性最大的有点:产生缓存,如果数据没有发生变化 直接从缓存取
                    reverseMsg:function () {
                        //数据反转
                        return this.msg.split('').reverse().join('')
                    },
                    fullName:function () {
                        return this.firstName +' '+ 'love'+ ' ' + this.lastName
                    }
                }
            })

        </script>
    </body>
    </html>
  • 相关阅读:
    在mac下使用ppk文件ssh到远程主机
    Openstack镜像和密码
    ubuntu下如何用命令行运行deb安装包
    python中使用@property
    linux里的vi怎么移动到最后一行
    Git 怎样保证fork出来的project和原project(上游项目)同步更新
    使用msgfmt编译多语言文件
    ubuntu创建文件夹快捷方式命令
    ssh: connect to host localhost port 22: Connection refused 问题
    excel中如何批量将所有的网址设为超链接
  • 原文地址:https://www.cnblogs.com/wuhui1222/p/14202562.html
Copyright © 2011-2022 走看看