vuedemo06

作者: 知识分享share | 来源:发表于2018-03-30 10:13 被阅读0次
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    </head>
    <body>
        <div id="app">
            <h1>computed计算属性</h1>
            <button v-on:click="a++">Add to A</button>
            <button v-on:click="b++">Add to B</button>
            <p>A-{{a}}</p>
            <p>B-{{b}}</p>
            <p>Age + A = {{addToA}}</p>
            <p>Age + B = {{addToB}}</p>
        </div>
    </body>
</html>
<script>
    new Vue({
        el:"#app",
        data:{
            a:'',
            b:'',
            age:20
        },
//      methods:{
//          addToA:function(){
//              return this.a+this.age;
//          },
//          addToB:function(){
//              return this.b+this.age;
//          }
//      }
        computed:{
            addToA:function(){
                return this.a+this.age;
            },
            addToB:function(){
                return this.b+this.age;
            }
        }
        
    })
</script>

相关文章

网友评论

      本文标题:vuedemo06

      本文链接:https://www.haomeiwen.com/subject/qwvbcftx.html