vue插槽slot
2020-02-06 21:09
246 查看
-
默认插槽slot: 就是没有名字(name)的插槽
代码如下,import Vue from 'vue' const comn={ template:` <div :style='style'> <div> <slot></slot> </div> </div> `, data(){ return{ style:{ width:'200px', height:'200px', border:'1px solid red' }, value:456 } } } new Vue({ components:{ comOne:comn, }, el:'#test', template:`<com-one> <span>this is default slot</span> </com-one>`, data(){ return { value:123 } } })
-
具名插槽slot: 就是给这个插槽起个名字,即有名字的插槽
import Vue from 'vue' const comn={ template:` <div :style='style'> <div> <slot name="header"></slot> </div> <div> <slot name="body"></slot> </div> </div> `, data(){ return{ style:{ width:'200px', height:'200px', border:'1px solid red' }, value:456 } } } new Vue({ components:{ comOne:comn, }, el:'#test', template:`<com-one> <span slot="header">this is header</span> <span slot="body">this is content</span> </com-one>`, data(){ return { value:123 } } })
-
作用域插槽slot-scope: 在组件上的属性,可以在组件元素内使用!
如下代码中aaa和bbb的值就是组件上的属性,slot-scope就是组件元素内的使用属性,它的值是一个对象import Vue from 'vue' const comn={ template:` <div :style='style'> <slot aaa="values" bbb="777"></slot> </div> `, data(){ return{ style:{ width:'200px', height:'200px', border:'1px solid red' }, values:456 } } } new Vue({ components:{ comOne:comn, }, el:'#test', template:`<com-one> <span slot-scope='props'>{{props.aaa}}{{props.bbb}}</span> </com-one>`, data(){ return { value:123 } } })
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- vue.js之slot插槽
- vue(9)----组件(2)slot插槽 动画过渡 动态组件
- vue动态组件和slot插槽
- vue插槽slot的理解与使用
- vue slot插槽的小技巧
- 深入解析vue使用插槽分发内容slot的用法
- 关于Vue中新老版本slot插槽,属性验证validator,过滤器fliter的用法
- vue中的作用域插槽--理解(slot-scope)
- vue - 插槽slot
- 个人笔记-----Vue中 slot 插槽【如有不对,欢迎指正】
- 详解vue2.6插槽更新v-slot用法总结
- 详解vue使用插槽分发内容slot的用法
- slot 作用域插槽,属性验证,过渡效果 && 动画,VUE生命周期,过滤器
- vue slot插槽的使用方法
- Vue插槽slot
- Vue中的插槽slot解析
- vue踩坑:slot插槽,vue路由传值
- vue 中的 $slot 获取 插槽的节点
- vue slot插槽理解
- 关于Vue slot插槽 我想说的事