-
Notifications
You must be signed in to change notification settings - Fork 476
/
12 computed v-for.html
70 lines (67 loc) · 1.59 KB
/
12 computed v-for.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="vue.js"></script>
<style>
.blue {
color: blue;
}
</style>
</head>
<body>
<div id="example-1">
<ul>
<!-- 计算属性 与列表渲染-->
<template v-for="item in filter1">
<li>{{ item}}</li>
</template>
</ul>
</div>
<script>
Vue.config.debug = true;
var example1 = new Vue({
el: '#example-1',
data: {
items: [{
msg: 'Foo'
}, {
msg: 'Bar'
}, {
msg: 'George'
}, {
msg: 'John'
}, {
msg: 'Thomas'
}, {
msg: 'James'
}, {
msg: 'Adrew'
}, {
msg: 'Martin'
}]
},
computed: {
filter1: function() {
/*
* itmes 字串长度大于4,形成列表
*/
self = this;
var arr=[];
for (var i = 0, l = self.items.length; i < l; i++) {
//console.log(self.items[i].msg);
var str_len = self.items[i].msg.length;
//.log(str_len);
if (str_len >=5){
arr.push(self.items[i].msg);
}
}
//console.log('arr:'+ arr);
return arr;
}
}
})
</script>
</body>
</html>