定义组件

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

 

使用场景1:如果想要动态的给child组件的dom结构添加节点,则需使用插槽。直接添加是无效的

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

定义插槽

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

使用场景1:如定义一个轮播组件,不固定轮播的内容,轮播内容按使用的场景临时添加

vue二十五:vue基础之slot插槽和具名插槽

使用

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

 

使用场景2:使用插槽实现在组件1上控制组件2是否展示

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

 

具名插槽,在预留了多个插槽时使用

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

vue二十五:vue基础之slot插槽和具名插槽

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue.js"></script>
</head>
<body>
<div ,
// data: {
// isShow: false
// }
// })


</script>
</body>
</html>

 

相关文章: