<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算方法属性侦听器</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="app">
{{fullName}}
{{age}}
</div>
<script>
var vm = new Vue({
el:"#app",
data:{
firstName:"Dell",
lastName:"Lee",
fullName:"Dell Lee",
age:28
},
//监听器(有缓存)
watch:{
firstName:function () {
console.log("computed once");
this.fullName = this.firstName + " " + this.lastName;
},
lastName:function () {
console.log("computed once");
this.fullName = this.firstName + " " + this.lastName;
}
}
//方法(无缓存)
/*methods:{
fullName : function () {
console.log("computed once");
return this.firstName + " " + this.lastName
}
}*/
//计算属性(有缓存)推荐
/*computed:{
fullName:function () {
console.log("computed once");
return this.firstName + " " + this.lastName
}
}*/
})
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算方法属性侦听器</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="app">
{{fullName}}
{{age}}
</div>
<script>
var vm = new Vue({
el:"#app",
data:{
firstName:"Dell",
lastName:"Lee",
fullName:"Dell Lee",
age:28
},
//监听器(有缓存)
watch:{
firstName:function () {
console.log("computed once");
this.fullName = this.firstName + " " + this.lastName;
},
lastName:function () {
console.log("computed once");
this.fullName = this.firstName + " " + this.lastName;
}
}
//方法(无缓存)
/*methods:{
fullName : function () {
console.log("computed once");
return this.firstName + " " + this.lastName
}
}*/
//计算属性(有缓存)推荐
/*computed:{
fullName:function () {
console.log("computed once");
return this.firstName + " " + this.lastName
}
}*/
})
</script>
</body>
</html>
1324

被折叠的 条评论
为什么被折叠?



