Vue计算属性

<!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">
        <input type="text" v-model="msg">
        <br/>
        {{message1()}}
        <br/>
        {{message2}}
    </div>
    <script>
        var m = {
             msg:"Hello world!"
        };
        var vm = new Vue({
            el:"#app",
            data: m,
            methods:{
                 message1:function(){
                     return this.msg.split('').reverse().join('');
                 }
            },
            computed:{
                message2:function(){
                    return this.msg.split('').reverse().join('');
                }
            }

        })
    </script>
 
</body>
</html>

  

posted @ 2021-02-25 11:25  田野与天  阅读(53)  评论(0编辑  收藏  举报