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

组件代码

<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>

使用案例

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

效果展示

在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-06 09:12:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-06 09:12:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-06 09:12:03       82 阅读
  4. Python语言-面向对象

    2024-02-06 09:12:03       91 阅读

热门阅读

  1. uniapp 之 base64转临时地址播放mp3

    2024-02-06 09:12:03       51 阅读
  2. Excel设置单元格下拉框(poi)

    2024-02-06 09:12:03       47 阅读
  3. docker 简单项目

    2024-02-06 09:12:03       51 阅读
  4. IEC61499 学习记录

    2024-02-06 09:12:03       55 阅读
  5. 大局观-高级后端工程师

    2024-02-06 09:12:03       39 阅读
  6. vmstat 监控虚拟内存,进程,CPU

    2024-02-06 09:12:03       40 阅读
  7. 面试复盘6——后端开发

    2024-02-06 09:12:03       54 阅读
  8. node.js 使用 elementtree 生成思维导图 Freemind 文件

    2024-02-06 09:12:03       56 阅读
  9. Spring Boot与Kafka集成教程

    2024-02-06 09:12:03       46 阅读
  10. ppi rust开发 python调用

    2024-02-06 09:12:03       42 阅读
  11. 第9章 SpringBoot综合项目实战——个人博客系统

    2024-02-06 09:12:03       51 阅读
  12. django解决Table ‘xx‘ already exists的方法

    2024-02-06 09:12:03       43 阅读