vue slot的使用方法

103 阅读1分钟
.slot的作用是:用于父组件向子组件传递标签

1.具名插槽
关于样式:写在父子组件都可以,推荐写在父组件
关于传值:写在父组件

![截屏2022-03-19 上午11.14.52.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2349b1e011a24e01a04e2b81c7030433~tplv-k3u1fbpfcp-watermark.image?)



2.作用域插槽(父组件可以获取子组件的值,传过去)

父组件写法:
![截屏2022-03-19 上午11.20.09.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9b8ff27c029a46148b63455de7d4eb35~tplv-k3u1fbpfcp-watermark.image?)

子组件写法:

![截屏2022-03-19 上午11.20.22.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8e1a9ca48d8249bb89390863c2ec9383~tplv-k3u1fbpfcp-watermark.image?)