【vue】作用域插槽(子组件向父组件传数据)

  • 子组件向父组件传递数据,之后在父组件定义的模板中渲染
    在这里插入图片描述

项目文件

在这里插入图片描述

传值过程

在这里插入图片描述
在这里插入图片描述

代码

App.vue

<template>
  <h2>App.vue</h2>
  <hr>
  <!-- 具名插槽 -->
  <Footer>
    <!-- <template #url="data">
      {{ data.title }}
      {{ data.user }}
    </template> -->
    <!-- 解构写法 -->
    <template #url="{ title, user }">
      {{ title }}
      {{ user }}
    </template>

  </Footer>

</template>

<script setup>
import Footer from "./components/Footer.vue";

</script>

<style lang="scss" scoped></style>


Footer.vue

<template>
    <h2>Footer.vue</h2>
    <slot name="url" title="abcdefg" user="100"/>
</template>

<script setup>

</script>

<style lang="scss" scoped>

</style>

参考

https://www.bilibili.com/video/BV1nV411Q7RX

最近更新

  1. TCP协议是安全的吗?

    2024-04-14 23:54:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-14 23:54:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-14 23:54:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-14 23:54:04       20 阅读

热门阅读

  1. boost asio同步接收发送UDP数据包

    2024-04-14 23:54:04       19 阅读
  2. Linux发送HTTP请求

    2024-04-14 23:54:04       14 阅读
  3. 华为OD-C卷-最长子字符串的长度(一)[100分]

    2024-04-14 23:54:04       14 阅读
  4. IP协议

    IP协议

    2024-04-14 23:54:04      14 阅读
  5. UE5+GIS技术应用场景介绍

    2024-04-14 23:54:04       14 阅读
  6. 7天八股速记之C++后端——Day 2

    2024-04-14 23:54:04       15 阅读