vue Render scopedSlots
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>
vue Render scopedSlots的更多相关文章
- vue render function
vue render function https://vuejs.org/v2/guide/render-function.html { // Same API as `v-bind:class`, ...
- vue render 渲染函数
vue render 渲染函数 经常看到使用render渲染函数的示例,而且在一些特殊情况下,确实更好使用,可以更加有效地细分组件,因而借助vue-element-admin来学习一波 render函 ...
- vue render里面的nativeOn
vue render里面的nativeOn的解释官方的解释是:// 仅对于组件,用于监听原生事件,而不是组件内部使用 `vm.$emit` 触发的事件. 官方的解释比较抽象 个人理解: 父组件要在子组 ...
- vue render function & dataset
vue render function & dataset https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In ...
- vue render & array of components & vue for & vue-jsx
vue render & array of components & vue for & vue-jsx https://www.cnblogs.com/xgqfrms/p/1 ...
- vue render html string
vue render html string shit element ui render string array relativeShowConvert(data) { // log(`data` ...
- vue render函数
基础 vue推荐在绝大多数情况下使用template来创建你的html.然而在一些场景中,你真的需要javascript的完全编程能力.这就是render函数.它比template更接近编译器 < ...
- vue render & JSX
vue在绝大多数使用template是没问题的,但在某些场合下,使用render更适合. 一.render函数 1.createElement 参数 createElement 可接受三个参数 1){ ...
- vue render {} 对象 说明文档
Vue学习笔记进阶篇——Render函数 http://www.mamicode.com/info-detail-1906336.html 深入data object参数 有一件事要注意:正如在模板语 ...
随机推荐
- 项目记录22-- tolua基于lua框架事件派发
每天晚上抽点时间写一点点就一点点,曾经不写博客可是如今.不为别的仅仅是为了告诉别人我还存在. 这几天在地铁上发现好多人都还在玩消除游戏,今天起码看到5个人,可是玩的版本号都不一样.看 ...
- 朴素的UNIX之-调度器细节
0.多进程调度的本质 我们都知道UNIX上有一个著名的nice调用.何谓nice,当然是"好"了.常规的想法是nice值越大越好,实际上,nice值越好,自己的优先级越低.那么为何 ...
- Chrome下使用百度地图报错Cannot read property 'minZoom' of undefined
问题:工作中在Google chome下面的js console里面测试百度地图API var map = new BMap.Map("container"); map.cente ...
- BZOJ 4710 容斥原理+dp
//By SiriusRen #include <cstdio> using namespace std; int n,m,a[1005]; typedef long long ll; l ...
- BZOJ 3667 Pollard-rho &Miller-Rabin
论O(1)快速乘和O(logn)快速乘的差距-. //By SiriusRen #include <cstdio> #include <algorithm> using nam ...
- 移动端 | Vue.js对比微信小程序基础语法
(1)vue 自定义组件与父组件的通信,props:[abb],可以看成自组建的一个自定义属性 (2)vue 模版语法{{}} 只能是在DOM中插入,<div>{{acc}}</di ...
- http协议以及防盗链技术
http协议,又称为超文本传输协议,顾名思义,http协议不仅能传输文本,还能传输图片,视频,压缩包等文件,http协议是建立在tcp/ip协议的基础之上的,http协议对php程序员来讲可以说是重中 ...
- javascript中封装scoll()方法
function scroll() { var scrollTop = window.pageYOffset || document.documentElement.scrollTop || docu ...
- log4j:WARN Please initialize the log4j system properly.解决方案
在使用quarz任务调度框架时的错误,实际上这个问题很常见,并不影响程序的使用,只是缺少日志输出,完整错误信息: log4j:WARN No appenders could be found for ...
- 给SearchView设置样式
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http:/ ...