-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13.1插槽示例.html
51 lines (51 loc) · 953 Bytes
/
13.1插槽示例.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>todos</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<body>
<div id="app">
<!-- 需要注意的地方使用叹号标明 -->
<todo-list :todos="todos">
<!-- !!!!! -->
<template v-slot:todo="{todo}">
<span v-if="todo.complete">√</span>
{{todo.text}}
</template>
</todo-list>
</div>
</body>
<script type="text/javascript">
var todoList = {
props:['todos'],
template:`
<ul>
<li v-for="todo,index in todos" :key="index">
<!-- !!!!!!! -->
<slot name="todo" :todo="todo">{{todo.text}}</slot>
</li>
</ul>
`
}
var vm = new Vue({
el:'#app',
components:{
todoList
},
data:{
todos:[{
text:'1',
complete:true
},{
text:'2',
complete:true
},{
text:'3',
complete:true
}]
}
})
</script>
</html>