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参数 有一件事要注意:正如在模板语 ...
随机推荐
- Qt 图像处理之 灰度变换
对图像的亮度.对照度进行变换是非经常常使用的一种图像处理操作,可是Qt 本身却没有提供对应的功能代码.因此我写了个简单的类来实现这些操作.我把这个类称为 BrightnessMapper. 代码例如以 ...
- tensorflow利用预训练模型进行目标检测(一):安装tensorflow detection api
一.tensorflow安装 首先系统中已经安装了两个版本的tensorflow,一个是通过keras安装的, 一个是按照官网教程https://www.tensorflow.org/install/ ...
- 【POJ 2482】 Stars in Your Windows
[题目链接] http://poj.org/problem?id=2482 [算法] 线段树 + 扫描线 [代码] #include <algorithm> #include <bi ...
- BZOJ 3729 splay维护DFS序+博弈论
思路: 这像是 阶梯Nim之类的东西 我们 直接把sg函数 设成mod(L+1)的 一棵子树 向下的奇数层上的石子xor起来 就是答案 有加点和改值的操作 就splay维护一下 //By Sirius ...
- Python学习小计
1.初学Python最好选择2.7版本,因为大部分Python书籍的示例代码是基于这个版本的 2.Python安装可以参考百度经验完成 如果在电脑上同时安装2个版本,则CMD启动时只需要: py -2 ...
- 将查询到的数据导出到Excel终结版
吐槽 最近新项目需要用到导出数据到Excel,试了试之前写的一篇博文,但是感觉那个不太好,主要原因是没能实现样式控制,今天我们就来介绍一种新的导出Excel方法,而且这种方法很轻量级,它利用xml生成 ...
- JavaScript系列--浅析原型链与继承
一.前言 继承是面向对象(OOP)语言中的一个最为人津津乐道的概念.许多面对对象(OOP)语言都支持两种继承方式::接口继承 和 实现继承 . 接口继承只继承方法签名,而实现继承则继承实际的方法.由于 ...
- 清北集训Day1T3 LYK loves jumping(期望DP)
题目描述 LYK在玩一个魔法游戏,叫做跳跃魔法. 有n个点,每个点有两个属性hi和ti,表示初始高度,和下降高度.也就是说,它初始时高度为hi,一旦LYK踩在这个点上,由于重力的影响,这个点的高度会下 ...
- Win10 build package error collections
1. 打包Released的时候出现问题意思是说 本地项目,类里有这个Visibility属性不能进行序列化 严重性 代码 说明 项目 文件 行 禁止显示状态 错误 error CS0029: 无法将 ...
- addEventListener()与removeEventListener(),追加事件和删除追加事件
addEventListener()与removeEventListener()用于追加事件和删除追加.所有的DOM节点中都包含这两种方法,并且它们都接受3个参数:要处理的事件名.作为事件处理程序的函 ...