【VUE】UniAPP之uview组件库,自定义tag封装,支持添加u-icon图标

组件代码

javascript 复制代码
<template>
    <view class="tag" :class="[props.mode, props.shape]">
        <slot name="left">
            <!-- icon图标 没有传入图标时不显示 -->
            <u-icon v-if="props.icon !== ''" :name="props.icon" :color="props.color" size="20" />
        </slot>
        {{ props.text }}
        <slot name="right"></slot>
    </view>
</template>

<script lang="ts" setup>
import { defineProps } from 'vue'
const props = defineProps({
    text: { //显示文本
        type: String,
        default: '自定义33'
    },
    color: { //颜色 主体颜色
        type: String,
        default: 'red'
    },
    mode: { //light	dark / plain
        type: String,
        default: 'light'
    },
    shape: { //形状square circle / circleLeft / circleRight
        type: String,
        default: 'circle'
    },
    icon: { //icon图标
        type: String,
        default: ''
    }

})
</script>

<style lang="scss" scoped>
$color: v-bind(color);

.tag {
    padding: 8rpx 22rpx;
    font-size: 20rpx;
    // border-radius: 36rpx;
    text-align: center;
    position: relative;
    z-index: 1;

    &::before {
        content: "";
        display: block;
        border-radius: 36rpx;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        opacity: 0.07;
        z-index: 0;
    }
}

// 形状
.tag.circle {
    border-radius: 36rpx;
}

.tag.circleLeft {
    border-radius: 36rpx;
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;
}

.tag.circleRight {
    border-radius: 36rpx;
    border-bottom-right-radius: 0;
    border-top-right-radius: 0;
}

// 模式

.tag.light {
    color: $color;
    border: 2rpx solid $color;

    &::before {

        background-color: $color;
    }
}

.tag.light2 {
    color: $color;

    &::before {

        background-color: $color;
    }
}

.tag.light3 {
    color: $color;
    background-color: #fff;

    &::before {
        // background-color: #fff;
        border: 1rpx solid $color;
    }
}

.tag.dark {
    color: #fff;
    background-color: $color;
}

.tag.plain {
    color: $color;
    border: 2rpx solid $color;
}
</style>

使用案例

javascript 复制代码
<tag text="分享" mode="light2" icon="zhuanfa" color="#3820d9" />
<tag text="重新生成" mode="light3" icon="reload" color="#000" />

效果展示

相关推荐
Setsuna_F_Seiei1 分钟前
前端转型 Agent 开发 05 之 Agent Hooks 与 Checkpointer(让 Agent 从全自动转变人为可掌控)
前端·agent·ai编程
百万蹄蹄向前冲2 小时前
风扇转了一晚上MVP专家团翻车事故
前端·人工智能
默_笙2 小时前
🏛 给 AI 配一间办公室:Harness Engineering 六大模块与它的实现
前端·javascript
linux_cfan3 小时前
videojs v10 源代码系列解读:14 · 谓词守卫:在运行时安全地调用能力
前端·javascript·音视频
kyriewen4 小时前
我扒了 10,221 条 JD:腾讯技术岗 75% 在要 AI
前端·人工智能·ai编程
郑州光合科技余经理4 小时前
同城外卖小程序开发:下单成功后,后台导出能不能对上用户端状态
开发语言·前端·git·后端·uni-app·php·ai编程
+VX:Fegn08955 小时前
计算机毕业设计|基于springboot + vue旅游管理系统(源码+数据库+文档)
java·开发语言·vue.js·spring boot·课程设计
雪芽蓝域zzs5 小时前
第 7 章:双 Y 轴组合图(柱状 + 折线,看板高频场景)
vue.js·echars
IT_陈寒5 小时前
Vue的响应式让我熬到凌晨三点,原来漏了这个小细节
前端·人工智能·后端
一 乐5 小时前
二手交易平台|基于springboot + vue二手交易平台(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序