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>