vue组件插槽
2019-07-30 21:08
106 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_34691738/article/details/97817422
1、在组件中加入自定义的html
slot标签为vue中特有标签,意为插槽,是指在组件中可以自定义插入dom;
//使用组件: <box-content> <div slot="header">header</div> <div slot="footer">footer</div> </box-content> //组件实现: Vue.component('box-content',{ template:`<div> <slot name="header"></slot> <div class="main">main</div> <slot name="footer"></slot> </div>`, data:function () { return{} }, props:{ } });
2、作用域插槽
组件插槽中数据显示形式由父组件决定;:slot="main"为插槽名称,slot-scope="scope"自定义作用域名称,可随意定义
//使用组件 <tem-slot> <template slot="main" slot-scope="scope"> <h3>{{scope.title}}</h3> <table> <tbody> <tr v-for="(item,index) in scope.data"><td>{{item}}</td></tr> </tbody> </table> </template> </tem-slot> //组件实现: Vue.component('tem-slot',{ template: `<div class="tem-slot"> <slot name="main" :data="rows" :title="title"></slot> </div>`, data:function () { return{ rows:[1, 2, 3, 4, 5], title:'title' } }, });
相关文章推荐
- Vue组件-使用插槽分发内容
- 详解Vue组件之作用域插槽
- Vue------第五天(关于组件的一些基础了解,包括组件的注册、Prop、自定义事件、使用插槽分发内容等)
- Vue 作用域插槽 列表组件 示例
- 从组件封装看Vue的作用域插槽的实现
- Vue 组件和插槽的理解与使用
- vue组件插槽
- vue组件,插槽
- Vue框架-基础知识(vue指令、实例生命周期、计算属性与监听属性、插槽理解、组件介绍、数据交互、ES6语法等)
- 使用Vue的slot插槽分发父组件内容实现高度复用、更加灵活的组件
- vue-插槽,动态组件和过滤器
- Vuejs slot插槽(显示子组件标签下的内容)
- vue组件(父子组件传值、非props特性、作用域插槽、动态组件、v-once)
- Vue组件--单个插槽
- vue(9)----组件(2)slot插槽 动画过渡 动态组件
- 使用Vue的slot插槽分发父组件内容实现高度复用、更加灵活的组件(推荐)
- VUE入门到实战--Vue非父子组件传值、插槽、动态组件和v-once
- 详解Vue组件插槽的使用以及调用组件内的方法
- React(12)组合(类似 Vue 组件的插槽)和继承
- Vue学习2-3.组件;4.插槽分发;5.动态组件;6.数据处理;