详解Vue slot插槽

这篇文章主要为大家介绍了Vue的slot插槽,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助

1.作用:让父组件可以向子组件指定位置插入html结构,也是一种组件间通信的方式,适用于父组件===>子组件(传的是HTML格式)。

父组件App:

详解Vue slot插槽_第1张图片

子组件Category:

详解Vue slot插槽_第2张图片

在父组件或者子组件里都可以给插槽中的内容设置样式,效果一样

作用域插槽:

1.理解:数据在组件的自身(Category),但根据数据生成的结构需要组件的使用者(APP)来决定。(games数据在Category组件中,但使用数据所遍历出来的结构由App组件决定)

子组件在给父组件传数据http://www.17wansf.com/thread-9082357-1-1.html
http://www.17wansf.com/thread-9080404-1-1.html
http://www.17wansf.com/thread-9080173-1-1.html
http://www.17wansf.com/thread-9079886-1-1.html
http://www.17wansf.com/thread-9078610-1-1.html
http://www.17wansf.com/thread-9077898-1-1.html
http://www.17wansf.com/thread-9077833-1-1.html
http://www.17wansf.com/thread-9077491-1-1.html
http://www.17wansf.com/thread-9077297-1-1.html
http://www.17wansf.com/thread-9076824-1-1.html
http://www.17wansf.com/thread-9089958-1-1.html
http://www.17wansf.com/thread-9105497-1-1.html
http://www.17wansf.com/thread-9089722-1-1.html
http://www.17wansf.com/thread-9089217-1-1.html
http://www.17wansf.com/thread-9088952-1-1.html
http://www.17wansf.com/thread-9088484-1-1.html
http://www.17wansf.com/thread-9088179-1-1.html
http://www.17wansf.com/thread-9087443-1-1.html
http://www.17wansf.com/thread-9083152-1-1.html
http://www.17wansf.com/thread-9082363-1-1.html
http://www.17wansf.com/thread-9080848-1-1.html
http://www.17wansf.com/thread-9080427-1-1.html
http://www.17wansf.com/thread-9080178-1-1.html
http://www.17wansf.com/thread-9080052-1-1.html
http://www.17wansf.com/thread-9079890-1-1.html
http://www.17wansf.com/thread-9078613-1-1.html
http://www.17wansf.com/thread-9077900-1-1.html
http://www.17wansf.com/thread-9077839-1-1.html
http://www.17wansf.com/thread-9077301-1-1.html
http://www.17wansf.com/thread-9076810-1-1.html
http://www.17wansf.com/thread-9075678-1-1.html
http://www.17wansf.com/thread-9075503-1-1.html
http://www.17wansf.com/thread-9123134-1-1.html
http://www.17wansf.com/thread-9113565-1-1.html
http://www.17wansf.com/thread-9113159-1-1.html
http://www.17wansf.com/thread-9113159-1-1.html

子:

详解Vue slot插槽_第3张图片

父:

使用atguigu这样一个对象接收是因为可能传了多个值

详解Vue slot插槽_第4张图片

作用域插槽也可以有名字name

总结

本篇文章就到这里了,希望能够给你带来帮助。

你可能感兴趣的:(Java,java)