最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Vue3實(shí)現(xiàn)印章徽章組件的示例代碼

 更新時(shí)間:2023年04月28日 08:34:41   作者:飛仔FeiZai  
這篇文章主要介紹了如何利用vue3實(shí)現(xiàn)簡(jiǎn)單的印章徽章控件,文中通過示例代碼講解詳細(xì),需要的朋友們下面就跟隨小編來一起學(xué)習(xí)學(xué)習(xí)吧

需要實(shí)現(xiàn)的組件效果:

該組件有設(shè)置顏色、大小、旋轉(zhuǎn)度數(shù)和文本內(nèi)容功能。

一、組件實(shí)現(xiàn)代碼

組件代碼文件結(jié)構(gòu)

src/components/StampBadge/src/StampBadge.vue 文件代碼

<template>
  <div
    class="first-ring"
    v-bind="getBindValue"
    :class="getStampBadgeClass"
    :style="{ transform: `rotate(${rotate}deg)` }"
  >
    <div class="second-ring" :class="getStampBadgeClass">
      <div class="third-ring" :class="getStampBadgeClass">
        <div class="forth-ring" :class="getStampBadgeClass">
          <div class="content-rectangle ellipsis" :class="getStampBadgeClass">
            <span class="">{{ content }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
  import { defineComponent } from "vue";
  export default defineComponent({
    name: "StampBadge",
    inheritAttrs: false,
  });
</script>

<script lang="ts" setup>
  import { computed, unref } from "vue";
  import { stampBadgeProps } from "./props";
  import { useAttrs } from "/@/hooks/core/useAttrs";

  const props = defineProps(stampBadgeProps);
  // get component class
  const attrs = useAttrs({ excludeDefaultKeys: false });
  const getStampBadgeClass = computed(() => {
    const { color, size } = props;
    return [
      {
        [`stamp-badge-${color}`]: !!color,
        [`stamp-badge-${size}`]: !!size,
      },
    ];
  });

  // get inherit binding value
  const getBindValue = computed(() => ({ ...unref(attrs), ...props }));
</script>

<style lang="less" scoped>
  .first-ring {
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .second-ring {
    background: #fff;
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .third-ring {
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .forth-ring {
    background: #fff;
    border-radius: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
  }

  .content-rectangle {
    background: #fff;
    font-weight: bold;
    text-align: center;
    position: absolute;
  }

  .ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  // primary
  .stamp-badge-primary.first-ring {
    background: #1890ff;
  }
  .stamp-badge-primary.third-ring {
    background: #1890ff;
  }
  .stamp-badge-primary.content-rectangle {
    border: 1px solid #1890ff;
    color: #1890ff;
  }
  // success
  .stamp-badge-success.first-ring {
    background: #52c41a;
  }
  .stamp-badge-success.third-ring {
    background: #52c41a;
  }
  .stamp-badge-success.content-rectangle {
    border: 1px solid #52c41a;
    color: #52c41a;
  }
  // error
  .stamp-badge-error.first-ring {
    background: #ff4d4f;
  }
  .stamp-badge-error.third-ring {
    background: #ff4d4f;
  }
  .stamp-badge-error.content-rectangle {
    border: 1px solid #ff4d4f;
    color: #ff4d4f;
  }
  // warning
  .stamp-badge-warning.first-ring {
    background: #faad14;
  }
  .stamp-badge-warning.third-ring {
    background: #faad14;
  }
  .stamp-badge-warning.content-rectangle {
    border: 1px solid #faad14;
    color: #faad14;
  }
  // info
  .stamp-badge-info.first-ring {
    background: #ccc;
  }
  .stamp-badge-info.third-ring {
    background: #ccc;
  }
  .stamp-badge-info.content-rectangle {
    border: 1px solid #ccc;
    color: #ccc;
  }
  // large
  .stamp-badge-large.first-ring {
    width: 84px;
    height: 84px;
  }
  .stamp-badge-large.second-ring {
    width: 80px;
    height: 80px;
  }
  .stamp-badge-large.third-ring {
    width: 74px;
    height: 74px;
  }
  .stamp-badge-large.forth-ring {
    width: 64px;
    height: 64px;
  }
  .stamp-badge-large.content-rectangle {
    width: 90px;
    font-size: 1.2rem;
  }
  // middle
  .stamp-badge-middle.first-ring {
    width: 64px;
    height: 64px;
  }
  .stamp-badge-middle.second-ring {
    width: 60px;
    height: 60px;
  }
  .stamp-badge-middle.third-ring {
    width: 56px;
    height: 56px;
  }
  .stamp-badge-middle.forth-ring {
    width: 48px;
    height: 48px;
  }
  .stamp-badge-middle.content-rectangle {
    width: 70px;
    font-size: 1rem;
  }
  // small
  .stamp-badge-small.first-ring {
    width: 54px;
    height: 54px;
  }
  .stamp-badge-small.second-ring {
    width: 50px;
    height: 50px;
  }
  .stamp-badge-small.third-ring {
    width: 46px;
    height: 46px;
  }
  .stamp-badge-small.forth-ring {
    width: 38px;
    height: 38px;
  }
  .stamp-badge-small.content-rectangle {
    width: 60px;
    font-size: 0.8rem;
  }
</style>

src/components/StampBadge/src/props.ts 文件代碼

export const stampBadgeProps = {
  color: {
    type: String,
    default: "primary",
    validator: (v) =>
      ["primary", "error", "warning", "success", "info"].includes(v),
  },
  /**
   * stamp badge size.
   * @default: middle
   */
  size: {
    type: String,
    default: "middle",
    validator: (v) => ["large", "middle", "small"].includes(v),
  },
  /**
   * stamp badge rotate deg.
   * @default: 0
   */
  rotate: { type: Number, default: 0 },
  content: { type: String, default: "Unknown" },
};

src/components/StampBadge/index.ts 文件代碼

import { withInstall } from "/@/utils";
import type { ExtractPropTypes } from "vue";
import stampbadge from "./src/StampBadge.vue";
import { stampBadgeProps } from "./src/props";

export const StampBadge = withInstall(stampbadge);
export declare type ButtonProps = Partial<
  ExtractPropTypes<typeof stampBadgeProps>
>;

src/utils/index.ts 文件代碼

export const withInstall = <T>(component: T, alias?: string) => {
  const comp = component as any;
  comp.install = (app: App) => {
    app.component(comp.name || comp.displayName, component);
    if (alias) {
      app.config.globalProperties[alias] = component;
    }
  };
  return component as T & Plugin;
};

二、組件全局注冊(cè)代碼

src/components/registerGlobComp.ts 文件代碼

import type { App } from "vue";
import { StampBadge } from "./StampBadge";

export function registerGlobComp(app: App) {
  app.use(StampBadge);
}

src/main.ts 文件代碼

import { createApp } from "vue";
import App from "./App.vue";
import { registerGlobComp } from "/@/components/registerGlobComp";

async function bootstrap() {
  // 創(chuàng)建應(yīng)用實(shí)例
  const app = createApp(App);
  // 注冊(cè)全局組件
  registerGlobComp(app);
  // 掛載應(yīng)用
  app.mount("#app", true);
}

bootstrap();

三、組件應(yīng)用代碼

<div style="width: 500px; height: 100px; position: relative">
  <StampBadge
    style="position: absolute; top: 0; right: 0"
    size="middle"
    color="success"
    content="已建檔"
    :rotate="45"
  />
</div>

到此這篇關(guān)于基于Vue3實(shí)現(xiàn)印章徽章組件的示例代碼的文章就介紹到這了,更多相關(guān)Vue3印章徽章組件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 淺談vue+vite項(xiàng)目部署會(huì)遇到的幾個(gè)問題

    淺談vue+vite項(xiàng)目部署會(huì)遇到的幾個(gè)問題

    本文主要介紹了vue+vite項(xiàng)目部署會(huì)遇到的幾個(gè)問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • 派發(fā)器抽離vue2單組件中的大量邏輯技巧

    派發(fā)器抽離vue2單組件中的大量邏輯技巧

    這篇文章主要為大家介紹了派發(fā)器抽離vue2單組件中的大量邏輯技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • 如何封裝Vue Element的table表格組件

    如何封裝Vue Element的table表格組件

    這篇文章主要介紹了如何封裝Vue Element的table表格組件,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2021-02-02
  • vue 組件中使用 transition 和 transition-group實(shí)現(xiàn)過渡動(dòng)畫

    vue 組件中使用 transition 和 transition-group實(shí)現(xiàn)過渡動(dòng)畫

    本文給大家分享一下vue 組件中使用 transition 和 transition-group 設(shè)置過渡動(dòng)畫,總結(jié)來說可分為分為 name 版, js 鉤子操作類名版, js 鉤子操作行內(nèi)樣式版,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2019-07-07
  • el-elementUI使用el-date-picker選擇年月

    el-elementUI使用el-date-picker選擇年月

    本文主要介紹了el-elementUI使用el-date-picker選擇年月,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-02-02
  • vue+iview框架實(shí)現(xiàn)左側(cè)動(dòng)態(tài)菜單功能的示例代碼

    vue+iview框架實(shí)現(xiàn)左側(cè)動(dòng)態(tài)菜單功能的示例代碼

    這篇文章主要介紹了vue+iview框架實(shí)現(xiàn)左側(cè)動(dòng)態(tài)菜單功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Vue2純前端實(shí)現(xiàn)文字流式輸出效果

    Vue2純前端實(shí)現(xiàn)文字流式輸出效果

    這篇文章主要為大家詳細(xì)介紹了Vue2純前端實(shí)現(xiàn)像chatGpt和Deepseek那樣的文字流式輸出效果的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),有需要的可以了解下
    2025-03-03
  • vue3+Echarts頁面加載不渲染顯示空白頁面的解決

    vue3+Echarts頁面加載不渲染顯示空白頁面的解決

    這篇文章主要介紹了vue3+Echarts頁面加載不渲染顯示空白頁面的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Vuex中State的使用方法

    Vuex中State的使用方法

    這篇文章主要介紹了Vuex中State的使用方法,Vuex 使用單一狀態(tài)樹,用一個(gè)對(duì)象就包含了全部的應(yīng)用層級(jí)狀態(tài),這也意味著,每個(gè)應(yīng)用將僅僅包含一個(gè) store 實(shí)例,需要的朋友可以參考下
    2023-11-11
  • 詳解VUE 對(duì)element-ui中的ElTableColumn擴(kuò)展

    詳解VUE 對(duì)element-ui中的ElTableColumn擴(kuò)展

    本篇文章主要介紹了詳解VUE 對(duì)element-ui中的ElTableColumn擴(kuò)展,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03

最新評(píng)論

永德县| 石阡县| 行唐县| 汾西县| 青岛市| 夏津县| 武宁县| 巴彦县| 平山县| 县级市| 陕西省| 佛山市| 旌德县| 台前县| 金秀| 荔波县| 蒙城县| 寿宁县| 加查县| 绍兴市| 辽中县| 河津市| 始兴县| 桃园县| 平湖市| 津市市| 台南县| 呼玛县| 佛坪县| 东至县| 德庆县| 秦皇岛市| 台中县| 汪清县| 南昌县| 无锡市| 汉寿县| 青川县| 凤庆县| 雅江县| 淅川县|