-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal.html
105 lines (90 loc) · 1.89 KB
/
cal.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<style>
*{
margin:0;
padding:0;
}
div {
width:400px;
background: pink;
margin:50px auto; /* make it in the center*/
padding:40px 80px;/* 40 means top and bottom ,while 80 means left and right*/
}
body{
font-family:Microsoft YaHei;
}
span {
float:right;
}
ul {
font-size:40px;
}
li {
list-style-type: none;
}
ul li {
margin-top:5px;
margin-right:35px;
background:palegreen;
}
ul li.active{
background-color:yellow;
}
p {
font-size:40px;
margin:10px 35px;
background: pink;
}
</style>
<div id="main" v-cloak>
<ul>
<li v-for="item in items" v-on:click="toggleActive(item)" v-bind:class="{'active':item.active}">
<!--v-bind的意思是说如果item.active是true,那么li就有<class="active">这个属性,否则就没有。这个是根据data中的
值来决定的。
v-on 依据点击,点击了就调用toggleActive(item)函数,这个函数改变active的属性,如果active是false,
就改成true,如果是true,就改成false。
-->
{{item.name}}<span>{{item.price}}</span></li>
</ul>
<p>Total:<span>{{total()}}</span></p>
</div>
<script>
var demo=new Vue({
el:'#main',
data:{
items:[{
name:'baicai',
price:200,
active:true,
},
{
name:'doujiao',
price:300,
active:false,
},
{name:'tudou',
price:220,
active:false,}]
},//, is necessary
methods:{
toggleActive: function(i){
i.active = !i.active;
},
// change active value, i是形参。
total:function(){
var total=0;
this.items.forEach(function(s){
if (s.active){
total+=s.price;
}
})//forEach over at here
return total;
}//total over at here
}//methods over at here
})//vue over at here
</script>