尽量少使用watch,可以用compute代替的就代替,watch比较消耗资源
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<h1>{{msg}}</h1>
<ul>
<li v-for = "item in arr">{{item}}</li>
</ul>
</div>
<script type="text/javascript">
var app = new Vue({
el:"#app",
data:{
msg:"hello vue",
arr:["小明",'小红','小黑']
},
watch:{
msg:function(mss){
console.log("监听事件------------------msg")
console.log(mss)
},
arr:function(val){
console.log("监听事件------------------arr")
this.msg = "监听事件------------------arr"
console.log(val)
}
}
})
</script>
</body>
</html>