将父组件的内容放到子组件指定的位置叫做内容分发solt

一、单个插槽

父组件app.vue

<template>
<div id="app">
<test-slot>
<span>我是父组件里的文字,但是我要被放到子组件里</span>
</test-slot>
</div>
</template> <script>
import testSlot from './components/testSlot'
export default {
components:{
testSlot
}
}
</script>

子组件testSlot.vue

<h3>test-slot</h3>
//父组件里的span会替换掉slot所以这里的123是看不见的
//如果父组件在使用子组件testSlot的时候不在里面加内容则这里的slot 123 会显示出来
<slot></slot>

二、多个插槽也叫具名插槽

具名插槽就是将某个名字的内容插到子组件对应名字里面去

三、作用域插槽(将子组件的值传到父组件供使用)

父组件app.vue;soltModel是子组件

<soltModel>
  1、首先父组件要定义一个 v-slot 这个属性名字 slotProps 自己起
  2、子组件中 定义一个 :slotDate="website" slotDate是自己写的名字,website就是子组件的数据
  3、这样父组件中:通过 slotProps.slotDate 就能拿到子组件中的数据
  4、父组件中:要在组件中 利用 template 来写

  <template v-slot="slotProps">
    {{slotProps.slotDate.id}}
  </template>
</soltModel>

子组件soltModel.vue

<template>
<h2>
<slot :slotDate="website">{{website.name}}</slot>
</h2>
</template>
<script>
export default {
data() {
return {
website:{
name: '我是子组件的数据',
id:
}
}
}
}
</script>

这样,父组件就访问到了子组件的数据

  

vue路由中的mate

在项目中肯定有这样的需求,那就是在某个页面的时候,顶部展示 现在当前的页面路径,如下图:

这个时候便用到了mate;

首先出现这个肯定是相对应不同的页面,也就是说对应不同的路由,我们在定义路由的时候:如下

复制代码
routes: [
{
path: '/',
name: 'login',
component: login
},{
path: '/Page',
name: 'Page',
component: Page,
children: [
{
path: '/UserList',
name: 'UserList',
component: UserList,
meta: ['数据列表', '用户列表'],
},{
path: '/OrderList',
name: 'OrderList',
component: OrderList,
meta: ['数据列表', '订单列表']
}
]
}
]

其次在 当前需要展示页面路径的地方:

<el-breadcrumb-item v-for="(item, index) in $route.meta" key="index">{{item}}</el-breadcrumb-item>

vue使用插槽分发内容slot的用法的更多相关文章

  1. vue组件-使用插槽分发内容(slot)

    slot--使用插槽分发内容(位置.槽口:作用: 占个位置) 官网API: https://cn.vuejs.org/v2/guide/components.html#使用插槽分发内容 使用组件时,有 ...

  2. vue 通过插槽分发内容

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

  3. vue2.0使用slot插槽分发内容

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

  4. Vue组件-使用插槽分发内容

    在使用组件时,我们常常要像这样组合它们: <app> <app-header></app-header> <app-footer></app-fo ...

  5. Vue:实践学习笔记(6)——使用SLOT分发内容

    Vue:实践学习笔记(6)——使用SLOT分发内容 Slot Slot是什么 Slot是父子组件的通讯方式,可以将父组件的内容显示到子组件之中. 使用SLOT前 比如我在定义组件的时候,在里面输入了X ...

  6. 通过UI库深入了解Vue的插槽的使用技巧

    Vue官网对于插槽的介绍比较简略,插槽本身也比较"烧脑",很容易看晕,我就一直没看懂,直到 使用了element-plus的组件的插槽. 其实我们可以换一个角度来理解插槽,就会豁然 ...

  7. Vue结合slot插槽分发父组件内容实现高度复用、更加灵活的dialog组件

    之前写过一篇关于vue实现dialog会话框组件的文章(http://www.cnblogs.com/fozero/p/8546883.html)[http://www.cnblogs.com/foz ...

  8. 使用Vue的slot插槽分发父组件内容实现高度复用、更加灵活的组件

    写在前面 之前写过一篇关于vue实现dialog会话框组件的文章http://www.cnblogs.com/fozero/p/8546883.html, 讲到了如何实现一个vue对话框组件,其中涉及 ...

  9. vue组件详解(四)——使用slot分发内容

    一.什么是slot 在使用组件时,我们常常要像这样组合它们: <app> <app-header></app-header> <app-footer>& ...

随机推荐

  1. C++ premier 中文版 学习笔记(第五章 表达式)

    解应用和自增组合使用的理解 由于后自增操作的优先级高于解引用操作,因此 *iter++ 等效于*(iter++).子表达式 iter++ 使 iter 加 1,然后返回 iter 原值的副本作为该表达 ...

  2. Spring Boot使用thymeleaf模板时报异常:template might not exist or might not be accessible by any of the configured Template Resolvers

    错误如下: template might not exist or might not be accessible by any of the configured Template Resolver ...

  3. Windows超级卸载工具Total Uninstaller,能完全卸载.NET Framework

    https://github.com/tsasioglu/Total-Uninstaller

  4. STM32的独立看门狗

    STM32 内 部自带了 2 个看门狗:独立看门狗(IWDG)和窗体看门狗(WWDG) STM32 的独立看门狗由内部专门的 40Khz 低速时钟驱动.即使主时钟发生问题.它也仍然 有效. 这里须要注 ...

  5. Axure RP一个专业的高速原型设计工具

    Axure RP是一个专业的高速原型设计工具.Axure(发音:Ack-sure),代表美国Axure公司.RP则是Rapid Prototyping(高速原型)的缩写. Axure简要介绍 Axur ...

  6. 迅为4412开发板Linux驱动教程/硬件知识及原理图的使用

    视频教程下载地址:http://pan.baidu.com/s/1pJwxUfL 嵌入式研发流程介绍 • PCB研发流程介绍 – 方案,原理图(网表) – layoutproject师(gerber文 ...

  7. php导入sql文件

    php导入sql文件 sql php php导入sql文件 基本思路 1.打开sql文件,放入一个变量(字符串类型)其中 2.使用正则替换掉其中的凝视("--"与"/** ...

  8. jsonArray和Java List对象互转,日期处理

    List转jsonArray : // 格式化日期 JsonConfig jsonConfig = new JsonConfig(); DSHJsonDateValueProcessor dshJso ...

  9. codeforces 915D Almost Acyclic Graph 拓扑排序

    大意:给出一个有向图,问能否在只去掉一条边的情况下破掉所有的环 解析:最直接的是枚举每个边,将其禁用,然后在图中找环,如果可以就YES,都不行就NO 复杂度O(N*M)看起来不超时 但是实现了以后发现 ...

  10. codeforces 898F Hash

    F. Restoring the Expression time limit per test 2 seconds memory limit per test 256 megabytes input ...