zoukankan      html  css  js  c++  java
  • Vue--computed

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv=" " content="ie=edge">
        <title>Document</title>
        <script src="https://cdn.bootcss.com/vue/2.6.6/vue.min.js"></script>
    </head>
    <body>
        <div id="app">
            <p>firstName:{{firstName}}</p>
            <p>lastName:{{lastName}}</p>
            <p>全名是:{{fullName}}</p>
            <button v-on:click="changeName">改姓</button>
        </div>
        <script>
            var app = new Vue({
                el:'#app',
                data:{
                    firstName:'王',
                    lastName:'花花'
                },
                methods: {
                    //changeName 定义一个方法改变 计算属性 fullName 的值
                    changeName:function(){
                        //修改计算属性 fullName 等于李花花
                        this.fullName = '李花花'
                        //上面一句等于触发了 fullName 属性的 setter
                    }
                },
                computed: {
                    fullName:{
                        //getter
                        get:function(){
                            console.log('这是啥时候出发的?')
                            return this.firstName+this.lastName
                        },
                        //setter  直接改变计算属性 fullName的值就可以触发setter this.fullName='XX'
                        set:function(newName){
                            console.log(newName)
                            console.log('我要改变了')
                            var name = newName
                            this.firstName = name.slice(0,1) //取新值的第一个字符
                            this.lastName = name.slice(1) //从新值的第二个字符开始取值
                        }
                    }
                }
            })
        </script>
    </body>

    </html>
  • 相关阅读:
    保持URL不变和数字验证
    centOS ftp key?
    本地环境测试二级域名
    linux 解决You don't have permission to access 问题
    php smarty section loop
    php header Cannot modify header information headers already sent by ... 解决办法
    linux部分命令
    Linux 里面的文件操作权限说明
    用IT网络和安全专业人士视角来裁剪云的定义
    SQL Server 2008 R2炫酷报表"智"作有方
  • 原文地址:https://www.cnblogs.com/x-yy/p/13099728.html
Copyright © 2011-2022 走看看