-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathtest-v3.html
42 lines (38 loc) · 1.03 KB
/
test-v3.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">
<title>Document</title>
</head>
<body>
<!-- 过滤列表中项目 -->
<!-- 浏览器控制台会报错:Uncaught TypeError: Cannot read properties of undefined (reading 'isActive') -->
<!-- <div id="app">
<div v-for="item in items" :key="item.id" v-if="item.isActive">
{{ item.name }}
</div>
</div> -->
<!-- 避免渲染应该被隐藏的列表 -->
<div id="app">
<div v-for="item of items" :key="item.id" v-if="shouldShowUsers">
{{ item.name }}
</div>
</div>
<script src="http://unpkg.com/vue@3"></script>
<script>
const app = Vue.createApp({
data() {
return {
shouldShowUsers: true,
items: [
{ id: 1, name: '张三', isActive: true },
{ id: 2, name: '李四', isActive: false }
]
}
},
}).mount('#app')
console.log(app.$options.render);
</script>
</body>
</html>