admin-vue/11-前端模块化开发Webpack(Node.js基础)/01-前端模块化的重要性/复习/插槽的使用.html

67 lines
1.5 KiB
HTML

<!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>
<div slot-scope="datas" slot="ul_list">
<h1>这是修改后的内容</h1>
<div v-for="item,index,key in datas">
<p>{{item[key].name}}</p>
</div>
</div>
</apps>
<br>
<apps></apps>
</div>
<template id="tpl">
<div>
<h1>子组件内容:</h1>
<div>
<slot name="li_list">
<ol>
<li v-for="list in lists">{{list.name}}</li>
</ol>
</slot>
</div>
<div>
<slot name="ul_list" :datas="lists">
<ul>
<li v-for="list in lists">{{list.name}}</li>
</ul>
</slot>
</div>
</div>
</template>
</body>
<script src="../../../00-tools/JavaScript/vue.js"></script>
<script>
new Vue({
el: "#app",
components: {
'apps': {
template: "#tpl",
data() {
return {
lists: [
{ id: 001, name: "张三", age: 10 },
{ id: 002, name: "李四", age: 22 },
{ id: 003, name: "王五", age: 12 },
]
}
}
}
}
})
</script>
</html>