<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue.js"></script>
<script src="vue-router2.js"></script>
</head>
<body>
<div id="app">
<input type="text" v-model="firstName">
<input type="text" v-model="lastName">
{{fullName}}
</div>
</body>
<script>
new Vue({
el:'#app',
data:{
firstName:'itcast',
lastName:'heima',
fullName:'itcast.heima'
},
watch:{
'firstName':function(newval,oldval){
this.fullName = this.firstName + this.lastName;
},
'lastName':function(newval,oldval){
this.fullName = this.firstName + this.lastName;
}
}
})
</script>
</html>
此外还可以监控路由
new Vue({
el :'#app',
router:router,//开启路由对象
watch:{
'$route':function(newroute,oldroute){
console.log(newroute,oldroute);
//在此函数中获取当前路由规则字符串
//可以针对特定的页面做特定的处理
}
}
})