vue233/10-组件化开发/09-组件插槽使用/03-作用域插槽的使用.html

48 lines
936 B
HTML
Raw Permalink Normal View History

2022-11-07 10:18:00 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<apps>
2022-11-07 15:17:03 +08:00
<div slot-scope="item">
<h1>这是父组件</h1>
<span v-for="li in item">
2022-11-07 20:08:25 +08:00
<span>{{li.join("-")}}</span>
2022-11-07 15:17:03 +08:00
</span>
2022-11-07 10:18:00 +08:00
</div>
</apps>
</div>
<template id="tpl">
<div>
2022-11-07 15:17:03 +08:00
<slot :item="list">
2022-11-07 10:18:00 +08:00
<ul>
<li v-for="item in list">{{item}}</li>
</ul>
</slot>
</div>
</template>
</body>
<script src="../../JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
components:{
'apps':{
template:"#tpl",
data(){
return {
list:['这是内容1','这是内容2','这是内容3']
}
}
}
}
})
</script>
</html>