vue官网API:

插槽:https://cn.vuejs.org/v2/guide/components-slots.html

JSX:https://cn.vuejs.org/v2/guide/render-function.html

说明:vue版本2.6.0以上语法

一、插槽模板传值

子组件:child.vue

<template>
<div>
<!-- 默认插槽 -->
<slot :info="info"></slot>
<!-- other插槽 -->
<slot name="other" :info="info2"></slot>
</div>
</template> <script>
export default {
data() {
return {
info: {
title: "标题一"
},
info2: {
title: "标题二"
}
};
}
};
</script>

父组件:parent.vue

<child>
<template v-slot:default="slotProps">
<div>
{{ slotProps.info.title }}
</div>
</template>
<template v-slot:other="slotProps">
<div>
{{ slotProps.info.title }}
</div>
</template>
</child>

结果:

二、插槽传值JSX写法

子组件:child.jsx

export default {
data() {
return {
info: {
title: "标题一"
},
info2: {
title: "标题二"
}
};
},
render() {
return (
<div>
{this.$scopedSlots.default({
info: this.info
})} {this.$scopedSlots.other({
info: this.info2
})}
</div>
);
}
};

父组件:parent.jsx

<child
scopedSlots={{
default: props => {
return (
<div style="line-height: 30px;">
{props.info.title}
</div>
);
},
other: props => {
return (
<div style="line-height: 30px;">
{props.info.title}
</div>
);
}
}}
/>

结果:

vue插槽(slot)的模板与JSX写法的更多相关文章

  1. vue 插槽slot

    本文是对官网内容的整理 https://cn.vuejs.org/v2/guide/components.html#编译作用域 在使用组件时,我们常常要像这样组合它们: <app> < ...

  2. Vue插槽 slot

    1. 什么是插槽 插槽slot 是往父组件中插入额外内容,实现组件的复用,一个插槽插入到一个对应的标签中 2. 实例: 一个组件中不允许有两个匿名插槽 </head> <body&g ...

  3. 三、深入Vue组件——Vue插槽slot、动态组件

    一.插槽slot() 1.1简单插槽slot [功能]用于从父组件中,通过子组件写成双标签,向子组件中放入自定的内容 parent.vue [1]首先把child写成双标签样式,把要插入的内容放双标签 ...

  4. vue 插槽slot总结 slot看这篇就够了

    一直模糊所以梳理一下,看了好多篇园友的文章和官网文档在这整理一下 默认插槽 //slot组件<template> <div class="slots"> s ...

  5. vue插槽slot的理解与使用

    一.个人理解及插槽的使用场景 刚开始看教程我的疑惑是为什么要用插槽,它的使用场景是什么,很多解释都是“父组件向子组件传递dom时会用到插槽”,这并不能很好的解决我的疑惑.既然你用了子组件,你为什么要给 ...

  6. vue 插槽 ------ slot 简单理解

    solt 插槽 内容分发 什么是插槽 Vue 实现了一套内容分发的 API,将 `` 元素作为承载分发内容的出口. 插槽显示的位置却由子组件自身决定,槽写在组件模板的什么位置,父组件传过来的模板将来就 ...

  7. Vue插槽slot理解与初体验 ~

    一.插槽的理解 1.官网介绍 Vue 实现了一套内容分发的 API,将 <slot> 元素作为承载分发内容的出口. 2.为什么使用插槽 Vue 中有一个重要的概念-组件,可以在开发中将子组 ...

  8. vue 插槽 slot

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. Vue 插槽 slot的简单实用

随机推荐

  1. 小程序公共模板template与公共js数据utils的引用实例

    在小程序项目开发中,经常会遇到公共模板与公共js数据的调用,这里结合自己的项目为这一需求做一简单介绍 目录截图 现在是有一个评论版块需要在几个页面里共用 先将评论版块的wxml剔出来放在templat ...

  2. 2018 IEEE极限编程大赛 题解

    去年742,今年72,也算一种小小的进步. 明年前30(笑 1. Drawing Rooted Binary Trees 给定一个树的中序和前序的遍历,要求输出这棵树(包括空格的) #include ...

  3. MyBatis的延迟加载和缓存机制

    延迟加载: 什么是延迟加载: MyBatis中的延迟加载,也称为懒加载,是指在进行关联查询时,按照设置延迟规则推迟对关联对象的select查询.延迟加载可以有效的减少数据库压力. MyBatis根据对 ...

  4. babel环境安装与编译

    babel:将浏览器不支持的ES6语法转为javascript 查看node是否安装: npm -v node -v 实例演示:在桌面新建part5目录在cmd命令行中 cd desktop cd p ...

  5. Dom中的一些接口

    节点都是单个对象,有时需要一种数据结构,能够容纳多个节点.DOM 提供两种节点集合,用于容纳多个节点:NodeList和HTMLCollection.这两种集合都属于接口规范.许多 DOM 属性和方法 ...

  6. 纪中5日T2 1565. 神秘山庄

    1565. 神秘山庄 (Standard IO) 原题 题目描述 翠亨村是一个神秘的山庄,并不是因为它孕育了伟人孙中山,更神秘的是山庄里有N只鬼.M只兔子,当然还有你.其中每秒钟: 1. 恰有两个生物 ...

  7. Hdu1042 N! (阶乘高精度模板)

    Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in ...

  8. ASP.NET简介及网页基础知识

    ASP:Active Server Page. asp.net属于.NET Framework的一部分,命名空间是System.Web,主要用于网络程序的开发. .net版本演化(asp.net和.n ...

  9. 2019-08-20 纪中NOIP模拟B组

    T1 [JZOJ3490] 旅游(travel) 题目描述 ztxz16如愿成为码农之后,整天的生活除了写程序还是写程序,十分苦逼.终于有一天,他意识到自己的生活太过平淡,于是决定外出旅游丰富阅历. ...

  10. apache poi下载流程

    apache poi下载官网:http://poi.apache.org/apidocs/4.1/ apache poi下载流程:https://blog.csdn.net/qq_31065001/a ...