首页 > 其他分享 >31-33 插槽Slots

31-33 插槽Slots

时间:2023-10-18 11:03:33浏览次数:32  
标签:33 插槽 31 传输 内容 组件 Slots message

基础

也是用来进行组件间的数据传输(父传子),内容是 模板的HTML内容

进阶

1. 渲染作用域:父级组件传输动态内容,在父级组件中定义数据
2. 插槽默认值: 插槽默认值,有内容传输过来的话,则不显示
3. 具名插槽:一个组件可以有多个插槽,为不同的插槽传输不同的内容,需要具体指定的名字name。

终极

在子组件中添加数据,父组件接收,然后再是 父组件传输内容给子组件。 那么,插槽中既有 父组件内容也有子组件的内容了

插槽就这么多内容了
1.App.vue

<template>
  <div>
    <!-- Slots_Base v-slot="slotProps" 接收子组件传过来的数据  -->
    <Slots_Base >
      <!-- 3.具名插槽,必须要在 template 模块中 -->
      <template v-slot:s1 >
        <p>具名插槽1:slot标题1</p>
        <!-- 1. 父级组件传输动态内容:在父级组件中定义数据 -->
        <p>{{ message }}</p>
      </template>

      <!-- v-slot: 可以简写 # -->
      <!-- 具名插槽 实现 父子组件相互传输数据 #s2="slotProps" -->
      <template #s2="slotProps" >
        <p>具名插槽2:slot标题2</p>
        <!-- 1. 父级组件传输动态内容:在父级组件中定义数据 -->
        <p>{{ message }}- {{ slotProps.msg }} </p>
      </template>
     </Slots_Base>

     <!-- 普通插槽 -->
    <A v-slot="slotProps">
    <h3> {{ message }}- {{ slotProps.msg }}</h3>
    </A>
  </div>
</template>

<script>
import Slots_Base from './components/Slots_Base.vue';
import A from './components/A.vue';
  export default {
    data() {
      return {
        message: "slot内容"
      }
    },
    components: {
      Slots_Base,
      A
    },
  }
</script>

<style lang="scss" scoped>

</style>
  1. 子组件1
<template>
    <div>
        <h3>基础插槽知识</h3>
        <!-- 2.插槽默认值,有内容传输过来的话,则不显示 -->
        <slot name="s1">插槽默认值,有内容传输过来的话,则不显示</slot>
        <hr>
        <slot name="s2" :msg="ChildMessage01"></slot>
        <hr>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                ChildMessage01: "子组件的数据"
            }
        },
    }
</script>

<style lang="scss" scoped>

</style>
  1. 子组件2
<template>
    <div>
        <slot :msg="ChildMessage"></slot>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                ChildMessage: "子组件数据"
            }
        },
    }
</script>

<style lang="scss" scoped>

</style>

标签:33,插槽,31,传输,内容,组件,Slots,message
From: https://www.cnblogs.com/zhanjianhai/p/17771483.html

相关文章

  • 20231017
    上午学了算法与数据结构中的线索二叉树睡了一整个下午帮助同学在关于开发的问题上躺床上看了编译器相关的书,挺有趣的。编译的几个阶段,语法分析,词法分析,抽象语法树,还有解释器生成器的使用什么的,熟悉但我也不怎么会用的正则表达式,好像编译器也并不是之前认知中的黑盒子了,现在就只......
  • Debian衍生桌面项目SpiralLinux12.231001发布
    SpiralLinux 是一个从Debian衍生出来的桌面项目,其重点是在所有主要桌面环境中实现简洁性和开箱即用的可用性。spiralLinux是为刚接触Linux世界的人们量身定制的发行版。这是GeckoLinux开发人员的创意,他更喜欢保持匿名。尽管他不愿透露姓名,但他的操作系统值得称赞,......
  • 20231014
    //accordingly,inflation,limit,maintain,outpace,rise,sharply,skyrocket,soar,steeply,bringabout,exchangerate,rawmaterial,taxrebateaccordingly-相应地,因此Accordinglymeansinawaythatisappropriateorsuitabletotheparticularcircumstan......
  • 20231017
    //advance,amount,balance,cheque,delivery,deposit,draft,flexible,honored,installment,maturity,mode,objection,payment,bymeansofadvance-预付款,预支Anadvancereferstoasumofmoneythatispaidorprovidedbeforeitisdueorbeforethecom......
  • 20231016
    //acceptable,candidly,feasible,workable,CIF,finalprice,FOB,landingcharge,stickerprice,subjectto,totalvalueacceptable-可接受的Acceptablemeanssomethingthatissatisfactory,fitting,orsuitable.Itreferstosomethingthatmeetstherequi......
  • 20231018
    //alter,alteration,amendment,cancel,change,coincide,delete,discrepancy,herein,insert,modify,obvious,perusal,revise,supplement,wordingalter-修改,改变Toaltermeanstomakechangesormodificationstosomething.Itinvolvesadjustingoradap......
  • 20231012
    //compromise,further,slash,closethedeal,halfmeasure,mutualbenefit,principleofmediocrity,profitmargin,reachsomemiddleground,rightinthemiddle,splitthedifference,strikeabalance,take...intoconsideration,that'sadealcompr......
  • 20231017
    20231017NOIP#22总结时间安排7:50~8:25看题,\(A\)会最一档,\(B,D\)不会。8:25~8:40写\(A\)最低档的暴力。8:40~9:30想了一会\(A\)感觉不太能延伸了,写\(B\)的\(n^2\)暴力。9:30~10:00写\(C\)链的特殊性质10:00~10:40想了个\(D\)的做法假了,写个爆搜结束了。......
  • 20231017打卡
    上午的第一堂课是算法与数据结构。在这门课上,我们深入学习了线索二叉树。线索二叉树是一种对二叉树进行优化的数据结构,它通过在节点中添加标志位,使得遍历二叉树时可以更快速地定位下一个节点。通过老师的讲解和课堂实践,我对线索二叉树的概念和实现方式有了更深入的了解。我通过课......
  • 20231017模拟赛
    异或帽子(hat)显然,\[B_i=(\oplus_{j=1}^{n}A_j)\oplusA_i\]因为\(2|n\),所以:\[S=\oplus_{i=1}^{n}B_i=\oplus_{i=1}^{n}A_i\]那么\[A_i=S\oplusB_i\]#include<bits/stdc++.h>usingnamespacestd;intn;ints;inta[200005];signedmain......