vue插槽嵌套

插槽嵌套的关键是父组件插槽的slot=子组件插槽的名称

子组件 slotTest1.vue

<template>
    <div>
        <slot name=‘slot1‘></slot>
    </div>
</template>

slotTest2.vue

<template>
    <slot-test1>
        <slot name=‘slot2‘ slot=‘slot1‘ record=‘我是插槽2‘>
        </slot>
    </slot-test1>
</template>
<script>
import slotTest1 from "./slotTest1"
export default {
  components: {
    slotTest1
  },
  data() {
    return {
    }
  }
}
</script>

父页面 test.vue

<template>
    <slot-test2>
        <div slot=‘slot2‘ :slot-scope=‘record‘>
            <p>{{record}}</p>
            <p>是真的吗?</p>
        </div>
    </slot-test2>
</template>
<script>
import slotTest2 from ‘./slotTest2‘
export default {
    components:{slotTest2},
    data(){
        return{
            record:‘年龄100岁‘

        }
    }
}
</script>

页面效果

原文地址:https://www.cnblogs.com/Dingzy/p/12170650.html

时间: 2024-08-30 18:03:25

vue插槽嵌套的相关文章

vue中嵌套页面 iframe 标签

vue中嵌套iframe,将要嵌套的文件放在static下面: <iframe src="../../../static/bear.html" width="300" height="300" frameborder="0" scrolling="auto"></iframe> src可以使用相对路径,也可使用服务器根路径http:localhost:8088/-等: <ifr

Vue插槽、ref和$refs用法

1.vue插槽 1.插槽的作用:以局部组件为例 插槽就是Vue实现的一套内容分发的API,将<slot></slot>元素作为承载分发内容的出口.插槽内可以是任意内容. (1)不带插槽的情况: <div id="app"> <vue> <h2>我是里面的内容</h2></vue> </div> <script> var Child = { template: '<div&g

vue 插槽slot

本文是对官网内容的整理 https://cn.vuejs.org/v2/guide/components.html#编译作用域 在使用组件时,我们常常要像这样组合它们: <app> <app-header></app-header> <app-footer></app-footer> </app> 注意两点: <app> 组件不知道它会收到什么内容.这是由使用 <app> 的父组件决定的. <app>

vue 组件嵌套

组件可以嵌套组件 组件可以嵌套自身组件,然后可以用递归思想来做 比如过树形菜单的时候,可以循环嵌套自身组件,知道没有子元素 列子 <body> <div id="app"> <m-tree :data="treeList"></m-tree> </div> </body> <script> Vue.component("m-tree-list",{ props:{

vue 插槽理解

插槽,顾名思义留一个坑在组件中,然后动态的去填坑,例如: //Child.vue 子组件 <template> <div> <slot></slot> </div> </template> <script> </script> <style lang=""> </style> //Parent.vue 引入子组件的文件 <template> <div

Vue插槽

插槽内容 Vue实现一套内容分发的API, 这套API基于当前的web组件规范草案,将<slot>元素作为承载分发内容的出口. <navigation-link url="/profile"> Your Profile </navigation-link> 然后在<navigation-link>的模板中可能会写为: <a :href="url" class="nav-link"> &l

vue插槽slot的理解与使用

一.个人理解及插槽的使用场景 刚开始看教程我的疑惑是为什么要用插槽,它的使用场景是什么,很多解释都是“父组件向子组件传递dom时会用到插槽”,这并不能很好的解决我的疑惑.既然你用了子组件,你为什么要给她传一些dom,直接去定义复用的子组件不就好了.后来想想觉得一个复用的组件在不同的地方只有些许变化,如果去重写子组件是很不明智的一件事,当然也可以将不同之处都写在子组件里,然后通过父组件传来的标识进行选择显示.其实质是对子组件的扩展,通过slot插槽向组件内部指定位置传递内容,即将<slot>&l

Vue插槽详解 | 什么是插槽?

作者 | Jeskson 来源 | 达达前端小酒馆 什么是插槽?插槽的指令为v-slot,它目前取代了slot和slot-scope,插槽内容,vue实例一套内容分发的api,将slot元素作为承载分发内容的出口. 组件的书写: <my-link url="/profile"> dada </my-link> 运用组件模板,可以在里面书写: <a v-bind:href="url" class="css-link"&

vue中嵌套路由

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con