-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVue计算属性.html
62 lines (56 loc) · 1.06 KB
/
Vue计算属性.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--view层,模板-->
<div id="app">
<p>currentTime1:{{currentTime1()}}</p>
<p>currentTime2:{{currentTime2}}</p>
</div>
<!--
计算属性
-->
<div id="app02">
<div>{{timeNow}}</div>
<div>{{timeNow}}</div>
</div>
<!--1.导入Vue.js-->
<script src="vue.js"></script>
<script type="text/javascript">
var vm = new Vue({
el:"#app",
data:{
message:"pan"
},
methods:{
currentTime1:function(){
return Date.now();//返回一个时间戳
}
},
computed:{
currentTime2:function(){//计算属性:methods,computed方法名不能重名,重名之后,只会调用methods的方法
this.message;
return Date.now();//返回一个时间戳
}
}
});
var vm01 = new Vue({
el: '#app02',
data: {
message: 'ok'
},
method:{
timeNow: function(){
return Date.now()
}
},
computed:{
timeNow: function (){
this.message
return Date.now()
}
}
})
</script>
</body>