Vue3标签(Tag)

news2024/9/30 21:30:48

APIs

参数说明类型默认值必传
closable标签是否可以关闭booleanfalsefalse
color标签颜色,预置多种常用颜色:'success', 'processing', 'error', 'warn', 'pink', 'red', 'orange', 'green', 'cyan', 'blue', 'purple'string‘’false
icon设置图标string | slot‘’false

Events

事件名称说明参数
close关闭时的回调(e: Event) => void

效果如下图:在线预览

在这里插入图片描述

创建标签组件Tag.vue

<script setup lang="ts">
import { ref, onMounted } from 'vue'
interface Props {
  closable?: boolean // 标签是否可以关闭
  color?: string // 标签颜色
  icon?: string // 设置图标 string | slot
}
withDefaults(defineProps<Props>(), {
  closable: false,
  color: '',
  icon: ''
})
const presetColor = ['success', 'processing', 'error', 'warn', 'default', 'pink', 'red', 'orange', 'green', 'cyan', 'blue', 'purple']
const hidden = ref(false)
const iconRef = ref()
const showIcon = ref(1)
onMounted(() => {
  showIcon.value = iconRef.value.offsetWidth
})
const emit = defineEmits(['close'])
function onClose (e: MouseEvent) {
  hidden.value = true
  emit('close', e)
}
</script>
<template>
  <div
    class="m-tag"
    :class="[color && presetColor.includes(color) ? 'tag-' + color:'', {'has-color': color && !presetColor.includes(color), hidden: hidden}]"
    :style="`background-color: ${color && !presetColor.includes(color) ? color : ''};`">
    <span class="m-icon" ref="iconRef" v-if="showIcon">
      <slot name="icon"></slot>
    </span>
    <span class="u-tag">
      <slot></slot>
    </span>
    <svg v-if="closable" @click="onClose" focusable="false" class="u-close" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 00203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg>
  </div>
</template>
<style lang="less" scoped>
.m-tag {
  font-size: 12px;
  line-height: 20px;
  display: inline-block;
  height: auto;
  color: rgba(0, 0, 0, 0.88);
  margin-inline-end: 8px;
  padding-inline: 7px;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  opacity: 1;
  transition: all 0.2s;
  text-align: start;
  .m-icon {
    margin-right: 5px;
    display: inline-flex;
    align-items: center;
    text-align: center;
    vertical-align: -0.125em;
  }
  .u-tag {
    display: inline-block;
  }
  .u-close {
    margin-inline-start: 3px;
    fill: rgba(0, 0, 0, 0.45);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    text-align: center;
    vertical-align: -0.125em;
    &:hover {
      fill: rgba(0, 0, 0, 0.88);
    }
  }
}
.tag-success {
  color: #52c41a;
  background: #f6ffed;
  border-color: #b7eb8f;
  :deep(svg) {
    fill: #52c41a;
  }
}
.tag-processing {
  color: #1677ff;
  background: #e6f4ff;
  border-color: #91caff;
  :deep(svg) {
    fill: #1677ff;
  }
}
.tag-error {
  color: #ff4d4f;
  background: #fff2f0;
  border-color: #ffccc7;
  :deep(svg) {
    fill: #ff4d4f;
  }
}
.tag-warn {
  color: #faad14;
  background: #fffbe6;
  border-color: #ffe58f;
  :deep(svg) {
    fill: #faad14;
  }
}
.tag-pink {
  color: #c41d7f;
  background: #fff0f6;
  border-color: #ffadd2;
  :deep(svg) {
    fill: #c41d7f;
  }
}
.tag-red {
  color: #cf1322;
  background: #fff1f0;
  border-color: #ffa39e;
  :deep(svg) {
    fill: #cf1322;
  }
}
.tag-orange {
  color: #d46b08;
  background: #fff7e6;
  border-color: #ffd591;
  :deep(svg) {
    fill: #d46b08;
  }
}
.tag-green {
  color: #389e0d;
  background: #f6ffed;
  border-color: #b7eb8f;
  :deep(svg) {
    fill: #389e0d;
  }
}
.tag-cyan {
  color: #08979c;
  background: #e6fffb;
  border-color: #87e8de;
  :deep(svg) {
    fill: #08979c;
  }
}
.tag-blue {
  color: #0958d9;
  background: #e6f4ff;
  border-color: #91caff;
  :deep(svg) {
    fill: #0958d9;
  }
}
.tag-purple {
  color: #531dab;
  background: #f9f0ff;
  border-color: #d3adf7;
  :deep(svg) {
    fill: #531dab;
  }
}
.has-color {
  color: #fff;
  border-color: transparent;
}
.hidden {
  display: none;
}
</style>

在要使用的页面引入

其中引入使用了 Vue3分割线(Divider)

<script setup lang="ts">
import Tag from './Tag.vue'
const onClose = (e: MouseEvent) => {
  console.log(e)
}
</script>
<template>
  <div>
    <h1>Tag 标签</h1>
    <h2 class="mt30 mb10">基本使用</h2>
    <Tag>Tag 1</Tag>
    <Tag><a href="https://blog.csdn.net/Dandrose">Link</a></Tag>
    <Tag closable @close="onClose">Tag 2</Tag>
    <h2 class="mt30 mb10">多彩标签</h2>
    <Tag color="pink">pink</Tag>
    <Tag color="red">red</Tag>
    <Tag color="orange">orange</Tag>
    <Tag color="green">green</Tag>
    <Tag color="cyan">cyan</Tag>
    <Tag color="blue">blue</Tag>
    <Tag color="purple">purple</Tag>
    <br/>
    <br/>
    <Tag color="#f50">#f50</Tag>
    <Tag color="#2db7f5">#2db7f5</Tag>
    <Tag color="#87d068">#87d068</Tag>
    <Tag color="#108ee9">#108ee9</Tag>
    <h2 class="mt30 mb10">预设状态的标签</h2>
    <Divider orientation="left">Without icon</Divider>
    <Tag color="success">success</Tag>
    <Tag color="processing">processing</Tag>
    <Tag color="error">error</Tag>
    <Tag color="warn">warning</Tag>
    <Tag color="default">default</Tag>
    <Divider orientation="left">With icon</Divider>
    <Tag color="success">
      <template #icon>
        <svg focusable="false" class="u-svg" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M699 353h-46.9c-10.2 0-19.9 4.9-25.9 13.3L469 584.3l-71.2-98.8c-6-8.3-15.6-13.3-25.9-13.3H325c-6.5 0-10.3 7.4-6.5 12.7l124.6 172.8a31.8 31.8 0 0051.7 0l210.6-292c3.9-5.3.1-12.7-6.4-12.7z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg>
      </template>
      success
    </Tag>
    <Tag color="processing">
      <template #icon>
        <svg focusable="false" class="u-spin" data-icon="sync" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M168 504.2c1-43.7 10-86.1 26.9-126 17.3-41 42.1-77.7 73.7-109.4S337 212.3 378 195c42.4-17.9 87.4-27 133.9-27s91.5 9.1 133.8 27A341.5 341.5 0 01755 268.8c9.9 9.9 19.2 20.4 27.8 31.4l-60.2 47a8 8 0 003 14.1l175.7 43c5 1.2 9.9-2.6 9.9-7.7l.8-180.9c0-6.7-7.7-10.5-12.9-6.3l-56.4 44.1C765.8 155.1 646.2 92 511.8 92 282.7 92 96.3 275.6 92 503.8a8 8 0 008 8.2h60c4.4 0 7.9-3.5 8-7.8zm756 7.8h-60c-4.4 0-7.9 3.5-8 7.8-1 43.7-10 86.1-26.9 126-17.3 41-42.1 77.8-73.7 109.4A342.45 342.45 0 01512.1 856a342.24 342.24 0 01-243.2-100.8c-9.9-9.9-19.2-20.4-27.8-31.4l60.2-47a8 8 0 00-3-14.1l-175.7-43c-5-1.2-9.9 2.6-9.9 7.7l-.7 181c0 6.7 7.7 10.5 12.9 6.3l56.4-44.1C258.2 868.9 377.8 932 512.2 932c229.2 0 415.5-183.7 419.8-411.8a8 8 0 00-8-8.2z"></path></svg>
      </template>
      processing
    </Tag>
    <Tag color="error">
      <template #icon>
        <svg focusable="false" class="u-svg" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4-66.1-.3c-4.4 0-8 3.5-8 8 0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670a8.32 8.32 0 00-1.9 5.2c0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4 66 .3c4.4 0 8-3.5 8-8 0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z"></path><path d="M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448 448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg>
      </template>
      error
    </Tag>
    <Tag color="warn">
      <template #icon>
        <svg focusable="false" class="u-svg" data-icon="exclamation-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M464 688a48 48 0 1096 0 48 48 0 10-96 0zm24-112h48c4.4 0 8-3.6 8-8V296c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8z"></path></svg>
      </template>
      warning
    </Tag>
    <Tag color="default">
      <template #icon>
        <svg focusable="false" class="u-svg" data-icon="clock-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path><path d="M686.7 638.6L544.1 535.5V288c0-4.4-3.6-8-8-8H488c-4.4 0-8 3.6-8 8v275.4c0 2.6 1.2 5 3.3 6.5l165.4 120.6c3.6 2.6 8.6 1.8 11.2-1.7l28.6-39c2.6-3.7 1.8-8.7-1.8-11.2z"></path></svg>
      </template>
      waiting
    </Tag>
    <Tag color="default">
      <template #icon>
        <svg focusable="false" class="u-svg" data-icon="minus-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M696 480H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h368c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg>
      </template>
      stop
    </Tag>
  </div>
</template>
<style lang="less" scoped>
.u-svg {
  display: inline-block;
  line-height: 1;
}
.u-spin {
  display: inline-block;
  line-height: 1;
  -webkit-animation: loadingCircle 1s infinite linear;
  animation: loadingCircle 1s infinite linear;
  @keyframes loadingCircle {
    100% {
      -webkit-transform: rotate(360deg);
      transform: rotate(360deg);
    }
  }
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/788762.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【深度学习】【Image Inpainting】Generative Image Inpainting with Contextual Attention

Generative Image Inpainting with Contextual Attention DeepFillv1 (CVPR’2018) 论文&#xff1a;https://arxiv.org/abs/1801.07892 论文代码&#xff1a;https://github.com/JiahuiYu/generative_inpainting 论文摘录 文章目录 效果一览摘要介绍论文贡献相关工作Image…

MySQL数据备份与恢复练习

目录 1.创建student和score表 2.为student表和score表增加记录 3.备份数据库school到/backup目录 4.备份MySQL数据库为带删除表的格式&#xff0c;能够让该备份覆盖已有数据库而不需要手动删除原有数据库 5.直接将MySQL数据库压缩备份 6.备份MySQL数据库某个(些)表。此例备…

『Python学习笔记』Python代码打包成pip包(可pip install)|查看安装torch、cuda和cudnn版本号

Python代码打包成pip包(可pip install)|查看安装torch、cuda和cudnn版本号 文章目录 一. pip包的好处二. 简单小例子2.1. 创建Python包2.2. 构建Python包2.3. 上传到PyPI2.4. pip安装测试 三. CLIP多模态模型相关例子3.1. Chinese-CLIP例子3.2. CLIP-ONNX例子3.3. 问题1和问题…

vue使用driver.js完成页面引导的功能

需求&#xff1a;用户首次进入的时候肯定不知道一些功能是干什么在哪里&#xff0c;之后给用户一个页面引导&#xff0c;教他怎么做。 点击插件driver.js官方文档 效果&#xff1a; 1.下载driverjs 我默认下载的是最新版 "driver.js": "^1.0.5",&#x…

MySQL 高级SQL语句(一)

目录 一、高级SQL语句&#xff08;进阶查询&#xff09; 1.1 select 1.2 distinct 1.3 where 1.4 and 和 or 1.5 in 1.6 between 1.7 通配符 1.8 like 1.9 order by 一、高级SQL语句&#xff08;进阶查询&#xff09; 先准备2个表 一个location表&#xff1a; use m…

私人记账本程序cashbook

什么是 cashbook &#xff1f; cashbook 是一个私人或家庭记账程序&#xff0c;支持私有化部署&#xff0c;商用或其他使用不受约束。建议使用者每年创建一个账本&#xff0c;图表功能可以起到分析全年数据的效果。 官方提供了演示站点&#xff0c;但不建议记录真实数据 演示账…

ardupilot 遥控的输入控制模式

目录 本节主要记录自己整理ardupilot的遥控器的输入控制模式:正常模式、简单模式、超简单模式的理解。 1.正常模式(有头模式) 在不用简单和超简单的模式的情况下,无人机操作员操作的控制输入是对应着不断旋转着的飞行器进行操作的。如上方图所示举例,当无人机操作员进行…

flask中的werkzeug介绍

flask中的werkzeug Werkzeug是一个Python库&#xff0c;用于开发Web应用程序。它是一个WSGI&#xff08;Web Server Gateway Interface&#xff09;工具包&#xff0c;提供了一系列实用功能来帮助开发者处理HTTP请求、响应、URLs等等。Werkzeug的设计非常灵活&#xff0c;可以…

基础入门-SpringBoot-自动配置特性

一、自动配好Tomcat 引入Tomcat依赖。配置Tomcat <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><version>2.3.4.RELEASE</version><scope>compile</sco…

同城跑腿小程序怎么做

同城跑腿小程序是一款基于地理位置的服务平台&#xff0c;为用户提供了便捷的日常生活服务。以下是该小程序的主要功能介绍&#xff1a; 1. 快速下单&#xff1a;用户可以通过小程序平台快速填写订单信息&#xff0c;包括取送地址、物品类型和重量等信息&#xff0c;然后选择合…

LabVIEW开发环境试验箱控制器

LabVIEW开发环境试验箱控制器 环境或气候试验箱是一种外壳&#xff0c;用于模拟各种材料&#xff08;包括工业产品、生物物质、复合材料、电子设备和航空航天部件&#xff09;的特定环境条件&#xff0c;并评估调节对这些材料的影响。 环境试验箱&#xff08;ETC&#xff09;…

存储过程——游标

1.游标 什么是游标&#xff0c;以及游标使用的相关语法。 #声明游标&#xff0c;存储查询结果集 #准备&#xff1a;创建表结构 #开启游标 #获取游标中的记录 #插入数据到新表中 #关闭游标 create procedure p11(in uage int) begindeclare uname varchar(100);declare upro …

Istio 故障注入与重试的实验

故障注入 Istio流量治理有故障注入的功能&#xff0c;在接收到用户请求程序的流量时&#xff0c;注入故障现象&#xff0c;例如注入HTTP请求错误&#xff0c;当有流量进入Sidecar时&#xff0c;直接返回一个500的错误请求代码。 通过故障注入可以用来测试整个应用程序的故障恢…

DYLD--动态链接器

概念 dyld&#xff08;the dynamic link editor&#xff09;是苹果的动态链接器&#xff0c;是苹果操作系统一个重要组成部分&#xff0c;在系统内核 XNU 完成 Mach-O 文件的加载&#xff0c;做好程序准备工作之后&#xff0c;交由 dyld 负责余下的工作。在 macOS 系统中&…

vue2引入lottie动画

说明下&#xff1a;如果你是vue3的话请移步&#xff1a;https://blog.csdn.net/qq_67801847/article/details/128386661&#xff0c;这里只针对vue2. 同时动画官网链接&#xff1a;lottie官网 实现思路&#xff1a; 1. 安装lottie-web (版本无所谓) 2. 在使用的页面引入组件 #…

一起来看看音频转文字怎么弄吧

从前有一个名叫小明的学生&#xff0c;他在学校里总是很喜欢录制各种有趣的音频&#xff0c;包括老师的讲课、同学们的笑声&#xff0c;以及校园里的各种声音。有一天&#xff0c;他在课堂上录下了老师的授课内容&#xff0c;想着晚上回家后再将它们转换成文字&#xff0c;便于…

网络安全(黑客)学习手册

1.什么是网络安全&#xff1f; 网络安全可以基于攻击和防御视角来分类&#xff0c;我们经常听到的 “红队”、“渗透测试” 等就是研究攻击技术&#xff0c;而“蓝队”、“安全运营”、“安全运维”则研究防御技术。 2.网络安全市场 一是市场需求量高&#xff1b; 二则是发展…

Python+大数据开发拿到25k的offer!

随着95后、00后的登场&#xff0c;80后好似成为“古早”的存在&#xff0c;看似被生活磨平了棱角的他们&#xff0c;其实也在渴望重新“支棱”起来。今天分享的这位80后的逆袭故事&#xff0c;希望你能感受到他的力量…… 学科 | Python大数据开发 校区 | 北京 薪资 | 25k 我…

【深度学习之YOLO8】视频流推断

官方V8模型下载 需要准备两个东西 simsun.ttc字体包YOLOv8官方模型成品 ScreenCapture屏幕图像类 import cv2 import mss import numpy as npclass ScreenCapture:"""parameters----------screen_resolution : Tuple[int, int]屏幕宽高&#xff0c;分别为x&a…

5.2.11.添加读写接口

5.2.11.添加读写接口 5.2.11.1、在驱动中添加 5.2.11.2、在应用中添加 5.2.11.3、测试 1. app.c #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>#define FILE "/dev/test" // 刚才mknod创建的设…