vue中的插槽slot

https://www.cnblogs.com/mandy-dyf/p/11528505.html

what

插槽是子组件中提供给父组件使用的一个占位符,用<slot></slot>标签表示,父组件可以在这个占位符中填充任何模板,如html,组件等,填充的内容会替换子组件中的<slot>标签。

1
2
3
4
5
6
7
8
9
10
11
//子组件
<template>
<div>
<h1>今天天气状况:</h1>
<slot></slot>
</div>
<template>
<script>
export default {
name: 'child'
}
1
2
3
4
5
6
// 父组件
<template>
<div>
<child><div>这是在父组件插入的内容</div></child>
</div>
</template>

输出:今天天气状况:这是在父组件插入的内容

文章目录
  1. 1. what
|