• 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>
  • 相关阅读:
    Android Studio “Project Structure”选项目录结构显示异常
    Android 不通过USB数据线调试的方法
    Android OpenGL ES 开发教程 从入门到精通
    Android NIO(Noblocking I/O非阻塞I/O)小结
    phpStudy3——往数据库中添加数据
    phpStudy2——PHP脚本访问MySql数据库
    phpStudy1——PHP文件获取html提交的参数
    php页面的基本语法
    安装使用phpStudy在本机配置php运行环境
    运行php网站需要安装什么
  • 原文地址:https://www.cnblogs.com/wuhui1222/p/14202562.html
Copyright © 2020-2023  润新知