vue3 笔记-插槽

ops/2024/10/21 5:19:44/

结构类似的模块,我们可以考虑用插槽,以便后续复用:

代码:

1.插槽

javascript"><script setup>
defineProps({title: {required: true,type: String},number: {required: true,type: Number}
})
</script><template><div class="px-5 py-4 rounded-lg bg-sky-400 h-fit hover:shadow-2xl transition ease-in-out duration-300"><slot name="header"><h2 class="text-white text-base mb-2">{{ title }}</h2></slot><hr class="border-gray-300 -mx-5"/><div class="pt-3 flex items-center justify-between"><slot name="number"><h2 class="font-bold text-white text-2xl hover:text-purple-600 transition ease-in-out duration-300">{{ number }}</h2></slot><span class="text-white hover:text-purple-600 transition ease-in-out duration-300"><slot name="icon"></slot></span></div></div>
</template>

2.使用插槽

javascript"><script setup>
import CardComponent from "@/components/CardComponent.vue";
</script><template><div class="flex gap-4 bg-gray-200 h-screen"><CardComponent title="文章总数" number="233" class="flex-1"><template #icon><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg></template></CardComponent><CardComponent title="文章分类总数" number="23" class="flex-1"><template #icon><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg></template></CardComponent><CardComponent title="标签总数" number="255" class="flex-1"><template #icon><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg></template></CardComponent><CardComponent title="访问量" number="033" class="flex-1"><template #icon><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg></template></CardComponent><CardComponent title="评论总数" number="987" class="flex-1"><template #icon><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg></template></CardComponent></div>
</template>


http://www.ppmy.cn/ops/127190.html

相关文章

Python爬虫进阶:高效数据采集的艺术

在当今数据驱动的世界里&#xff0c;高效的网络爬虫技术已经成为每个数据科学家和后端工程师的必备技能。本文将深入探讨一些高级的Python爬虫技术&#xff0c;这些技术不仅能够大幅提升你的爬虫效率&#xff0c;还能帮助你应对各种复杂的爬虫场景。 1. 异步爬虫&#xff1a;协…

基于Java微信小程序的高校教务管理系统的详细设计和实现(源码+lw+部署文档+讲解等)

详细视频演示 请联系我获取更详细的演示视频 项目运行截图 技术框架 后端采用SpringBoot框架 Spring Boot 是一个用于快速开发基于 Spring 框架的应用程序的开源框架。它采用约定大于配置的理念&#xff0c;提供了一套默认的配置&#xff0c;让开发者可以更专注于业务逻辑而不…

linux命令之lspci用法

lspci 显示当前主机的所有PCI总线信息 补充说明 lspci命令 用于显示当前主机的所有PCI总线信息&#xff0c;以及所有已连接的PCI设备信息。 语法 lspci(选项)选项 -n&#xff1a;以数字方式显示PCI厂商和设备代码&#xff1b; -t&#xff1a;以树状结构显示PCI设备的层次…

maxkb软件 Windows系统安装教程

文章目录 maxkb介绍安装依赖安装流程maxkb介绍 MaxKB = Max Knowledge Base,是一款基于大语言模型和 RAG 的开源知识库问答系统,广泛应用于企业内部知识库、客户服务、学术研究与教育等场景。 开箱即用:支持直接上传文档 / 自动爬取在线文档,支持文本自动拆分、向量化和 R…

道路垃圾识别数据集 含pt模型界面 18类 共7542张图片,xml和txt标签都有;

道路垃圾识别数据集 含pt模型&界面 18类 共7542张图片&#xff0c;xml和txt标签都有&#xff1b; YOLO道路垃圾识别系统 系统概述 名称&#xff1a;YOLO道路垃圾识别系统 图片数量&#xff1a;7542张标注格式&#xff1a;XML和TXT&#xff08;支持YOLO格式&#xff09;类…

WebServer构建响应 发送响应

1.构建响应 构建响应流程如下 确认方法根据不同方法&#xff0c;以不同方法提参确认访问资源如果用户的URL没有指明要访问的某种资源(路径)&#xff0c;虽然浏览器默认会添加/&#xff0c;但是依旧没有告知服务器&#xff0c;要访问什么资源 此时&#xff0c;默认返回对应服务…

科研绘图系列:R语言突出强调部分的饼图(pie plot)

文章目录 介绍加载R包数据数据预处理画饼图画图例合并图形系统信息介绍 饼图(Pie Chart),也称为圆图(Circle Graph),是一种圆形的统计图表,通过将圆分成若干扇形来展示数据的比例关系。每个扇形的角度大小代表了相应数据在总量中的占比。饼图的特点包括: 比例展示:直…

基于微信小程序的智能校园社区服务推荐系统

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、Vue项目源码、SSM项目源码、微信小程序源码 精品专栏&#xff1a;…