vue计算属性和监听
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src="vue/vue.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div id="app">
<!-- 实现反转meg过程 -->
<div>{{meg.split("").reverse().join("")}}</div>
<!-- 由于反转meg的过程,很长,在布局中很难看,所以用计算属性(computed),进行简化 -->
<div>{{reversedString}}</div>
<!-- 通过计算属性,将原来很长的计算过程,封装在属性computed中,是页面简化,就是把计算过程隐藏代替(看起来页面简单) -->
<div>
<input type="text" v-model = 'text'>
<input type="text" v-model = 'texr'>
<span>{{tyop}}</span>
</div>
</div>
<script>
var app = new Vue({
el:'#app',
data:{
text:'Tom',
texr:'jimi',
meg:'hellow',
tyop:'',
},
computed:{
reversedString:function(){
return this.meg.split("").reverse().join("");
}
},
watch:{
text:function(val){
this.tyop = val + '' + this.texr;
},
texr:function(val){
this.tyop = this.text + '' + val;
}
},
})
</script>
</body>
</html>