-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.vue的计算属性复杂.html
42 lines (39 loc) · 1005 Bytes
/
16.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id = 'app'>
<h1>总价格:{{ totalPrice }}<h1>
</div>
<script src= 'https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script>
<script>
const vue = new Vue({
el: '#app',
data: {
book: [
{id: 110,name: "html",price: 105},
{id: 112,name: "css",price: 125},
{id: 115,name: "javascript",price: 135},
{id: 118,name: "vue",price: 145}
]
},
computed: {
totalPrice:function(){
let result= 0
for(let i=0; i < this.book.length; i++){
result +=this.book[i].price
}
return result
for(let i in this.book){}
for(let book of this.book){}
}
},
})
</script>
</body>
</html>