<div>{{method()}}</div>
<div>{{method()}}</div>
<div>{{computed1}}</div>
<div>{{computed1}}</div>
data:{
score:10
},
methods:{
method:function(){
console.log("method");
return score+10;
},
computed:{
console.log("computed");
computed1:function(){
return score+10;
},
侦听
使用场景:当数据变化时,其他数据需要跟着变化
<input type = "text" v-model = "uname"/>
data:{
uname:"",
tip:""
},
methods:{
method:function(uname){
var that = this;
setTimeOut({
function(){
if(uname == "admin")
that.tip = "用户名已存在";
else
that.tip = "可以使用";
}
},2000);
}
}
watch:{
uname:function(val){
this.method(val);
this.tip = "正在验证";
}
}