vue Render中slots的使用
来源:互联网 发布:java培训机构 知乎 编辑:程序博客网 时间:2024/05/02 02:39
render 中 slot 的一般默认使用方式如下:
this.$slots.default 对用 template的<slot>的使用没有name 。
想使用多个slot 的话。需要对slot命名唯一。使用this.$slots.name 在render中添加多个slot。
<body> <div class="" id="app"> <myslot> <div>this is slot</div> </myslot> </div> <script> Vue.component('myslot',{ render:function(createElement){ var he=createElement('div',{domProps:{innerHTML:'this child div'}}); return createElement('div',[he,this.$slots.default]) } }); var app=new Vue({ el:'#app' }) </script> </body>
多个slot的使用
<body> <div class="" id="app"> <myslot> <div slot="name1">this is slot</div> <div slot="name2">The position is slot2 </div> </myslot> </div> <script> Vue.component('myslot',{ render:function(createElement){ var he=createElement('div',{domProps:{innerHTML:'this child div'}}); return createElement('div',[he,this.$slots.name2,this.$slots.name1]) } }); var app=new Vue({ el:'#app' }) </script> </body>
在vue2.1.0新添加了scope(虽然感觉有点怪,但是用习惯了,还蛮好用的)
同样给出一般使用和多个使用示例,
<body> <div class="" id="app"> <myslot> <template scope="props"> <div>{{props.text}}</div> </template> </myslot> </div> <script> Vue.component('myslot',{ render:function(createElement){ var he=createElement('div',{domProps:{innerHTML:'this child div'}}); return createElement('div',[he,this.$scopedSlots.default({ text:'hello scope' })]) } }); var app=new Vue({ el:'#app' }) </script> </body>
多个$scopedSlot的使用
<body> <div class="" id="app"> <myslot> <template slot="name2" scope="props"> <div>{{props.text}}</div> </template> <template slot="name1" scope="props"> <span>{{props.text}}</span> </template> </myslot> </div> <script> Vue.component('myslot',{ render:function(createElement){ var he=createElement('div',{domProps:{innerHTML:'this child div'}}); return createElement('div', [he, this.$scopedSlots.name1({ text:'hello scope' }), this.$scopedSlots.name2({ text:'$scopedSlots using' })]) } }); var app=new Vue({ el:'#app' }) </script> </body>
0 0
- vue Render中slots的使用
- Vue中render方法的使用
- Vue的Render函数
- Xamarin中Render的使用
- Vue 同时监视多个值得变化传给render,并在render中使用
- vue slots 组件的组合/分发
- vue iview组件表格 render函数的使用
- 在QThread中使用slots
- 了解VUE的render函数
- vue2.0 Render函数 Render具体能做点什么 Render应用场景 Render在.vue无法使用
- zend_controller_action中initView()与render()的使用
- ruby on rails 中render的使用
- yii 中render 和renderpartial的使用
- grails中render、respond、redirect的使用
- Vue.js render方法使用详解
- 粗解Vue.js的render方法
- 粗解Vue.js的render方法
- 第八章:vue2中render与ref的使用
- 【IO】java IO 总结
- 在windows下通过的IntelliJ IDEA通过Ant构建工具远程提交Spark应用程序
- Centos常用快捷操作
- Form表单之radio单选框操作
- 分块数组
- vue Render中slots的使用
- nginx开启目录浏览下载功能(autoindex)
- 35. Search Insert Position
- Java基础(1)
- redis集群和kafka集群作为消息队列比较
- 20170111计划
- 【DVB】【奥地利】Austria数字电视广播spec
- Webview加载网页时出现NET::ERR_CACHE_MISS的错误
- Android Studio、Gradle常见错误、设置