当前位置: 首页 > news >正文

vue3 笔记-插槽

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

代码:

1.插槽

<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.使用插槽

<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.lryc.cn/news/464120.html

相关文章:

  • C# 字符串常用方法
  • 字节跳动青训营——入营考核解答(持续更新中~~~)
  • JavaWeb合集15-Apache POI
  • Threejs 实现3D 地图(01)创建基本场景
  • snmpdelta使用说明
  • Hadoop集群安装
  • VuePress集成到Vue项目的方法
  • 【ROS】ROS局域网下多机通讯方法
  • linux 系统怎么使用
  • Java线程池知识点梳理
  • SFT、RLHF、DPO、IFT —— LLM 微调的进化之路_如何搭建自己的dpo
  • CSS 选择器简单回顾
  • uniapp配置微信小程序分包(分包优化)
  • MySQL-10.DML-添加数据insert
  • ARM/Linux嵌入式面经(四八):tp-link联洲国际
  • 代码实践篇四 形状检测与规则重建
  • JVM(HotSpot):GC之垃圾回收阶段
  • Go 项目如何集成类似mybatisPlus插件呢?GORM走起!!
  • 《深度学习》Dlib库 CNN卷积神经网络 人脸识别
  • 滚雪球学Redis[7.1讲]:Redis实战案例
  • WordPress外部图片本地化插件
  • Linux基础-shell的简单实现
  • Tomcat日志文件详解及catalina.out日志清理方法
  • react 中的hooks中的useState
  • STM32学习笔记---DMA
  • Cesium 实战 - 自定义纹理材质 - 立体墙(旋转材质)
  • 进程间关系与守护进程
  • 金山翻译接口逆向
  • unified-runtime编译与验证
  • 【Python】最详细--基础语法