【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" />

效果展示

相关推荐
云水一下3 小时前
TypeScript 从零基础到精通(五):高级类型与泛型
前端·javascript·typescript
counterxing3 小时前
vibe coding 之后,我更不想打字了
前端·agent·ai编程
copyer_xyf4 小时前
Python 模块与包的导入导出
前端·后端·python
研☆香4 小时前
es6新特性功能介绍(四)
前端·ecmascript·es6
微扬嘴角4 小时前
React篇1--JSX语法规则、组件、组件实例的3大特性
前端·react.js·前端框架
copyer_xyf4 小时前
Python venv 虚拟环境
前端·后端·python
无聊的老谢5 小时前
Vue 3 + TypeScript 构建大型电信运维平台的前端架构设计
前端·vue.js·typescript
xiaofeichaichai5 小时前
Map / Set / WeakMap / WeakSet
前端·javascript
李可以量化5 小时前
成交量的终极量化策略:价量共振指标完整实现(下篇)
前端·数据库·人工智能
copyer_xyf6 小时前
Python 如何同时做很多事:进程、线程、协程
前端·后端·python