美文网首页
插槽(Vue2)

插槽(Vue2)

作者: QYCD | 来源:发表于2023-05-15 11:04 被阅读0次

Vue官网
仅仅是个人学习的记录

组件:

<template>
  <div class="container">
    <header>
      <slot name="header">这是Header</slot>
    </header>
    <main>
      <slot>这是Main</slot>
    </main>
    <footer>
      <slot name="footer">这是Footer</slot>
    </footer>
    <van-button @click="sayHi">
      <slot name="submit">Submit</slot>
    </van-button>
  </div>
</template>

<script>
export default {
  name: "ChildModule",
  methods: {
    sayHi() {
      this.$toast({message: 'Hi'})
    },
  },
}
</script>

<style scoped lang="less">

</style>

调用组件:

<child-module>
      <template #header>
        我是顶部
      </template>
      <template #default>
        我是主体
      </template>
      <template #footer>
        我是尾部
      </template>
      <template #submit>
        say hi
      </template>
    </child-module>
image.png

相关文章

  • 18、Vue3 作用域插槽

    作用域插槽:让插槽内容能够访问子组件中,vue2中作用域插槽使用slot-scope,vue3中使用v-slot ...

  • (十八)补充-Vue3中插槽的使用

    本章我们将了解到的是vue3中常用插槽的使用; vue3中的插槽是在用的时候和vue2的区别略有不同,常见插槽使用...

  • vue----slot插槽

    插槽分类 匿名插槽 具名插槽 作用域插槽

  • vue中slot插槽的使用

    插槽的种类:1、默认插槽、具名插槽、作用域插槽、解构插槽、动态插槽几种。转原文:https://www.jians...

  • vue3中的插槽

    插槽 默认插槽 具名插槽,v-slot可以简写为# 动态插槽 #[dynamicSlotName] 作用域插槽(...

  • vue2 vs vue3 插槽

    前言:插槽的使用其实是很简单,你只需要明白两点: 1.插槽是使用在子组件中的。 2.插槽是为了将父组件中的子组件模...

  • 2.插槽

    匿名插槽 具名插槽 作用域插槽

  • 深入理解vue中的slot与slot-scope(自 2.6.0

    单个插槽 | 默认插槽 | 匿名插槽首先是单个插槽,单个插槽是vue的官方叫法,但是其实也可以叫它默认插槽,或者与...

  • vue 插槽 slot

    插槽使用 普通插槽 具名插槽 使用具名插槽 从插槽里面传值出来如何接收? 如: 如何判断某个插槽是否被使用 组件内...

  • vue插槽

    默认插槽(没有名字的插槽) 具名插槽(带名字的插槽) 老版 2.6.0以前 新版 作用域插槽(父组件可以获取子组件...

网友评论

      本文标题:插槽(Vue2)

      本文链接:https://www.haomeiwen.com/subject/mbvssdtx.html