
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
@ophiuchus/badge
Advanced tools
在右上角展示徽标数字或小红点。
import Vue from 'vue';
import Badge from '@ophiuchus/badge';
Vue.use(Badge);
设置 content 属性后,Badge 会在子元素的右上角显示对应的徽标,也可以通过 dot 来显示小红点。
<sf-badge :content="5">
<div class="child" />
</sf-badge>
<sf-badge :content="10">
<div class="child" />
</sf-badge>
<sf-badge content="Hot">
<div class="child" />
</sf-badge>
<sf-badge dot>
<div class="child" />
</sf-badge>
<style>
.child {
width: 40px;
height: 40px;
background: #f2f3f5;
border-radius: 4px;
}
</style>
设置 max 属性后,当 content 的数值超过最大值时,会自动显示为 {max}+。
<sf-badge :content="20" max="9">
<div class="child" />
</sf-badge>
<sf-badge :content="50" max="20">
<div class="child" />
</sf-badge>
<sf-badge :content="200" max="99">
<div class="child" />
</sf-badge>
通过 color 属性来设置徽标的颜色。
<sf-badge :content="5" color="#1989fa">
<div class="child" />
</sf-badge>
<sf-badge :content="10" color="#1989fa">
<div class="child" />
</sf-badge>
<sf-badge dot color="#1989fa">
<div class="child" />
</sf-badge>
通过 content 插槽可以自定义徽标的内容,比如插入一个图标。
<sf-badge>
<div class="child" />
<template #content>
<sf-icon name="success" class="badge-icon" />
</template>
</sf-badge>
<sf-badge>
<div class="child" />
<template #content>
<sf-icon name="cross" class="badge-icon" />
</template>
</sf-badge>
<sf-badge>
<div class="child" />
<template #content>
<sf-icon name="ellipsis" class="badge-icon" />
</template>
</sf-badge>
.badge-icon {
display: block;
font-size: 10px;
line-height: 16px;
}
当 Badge 没有子元素时,会作为一个独立的元素进行展示。
<sf-badge :content="20" />
<sf-badge :content="200" max="99" />
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| content | 徽标内容 | number | string | - |
| color | 徽标背景颜色 | string | #ee0a24 |
| dot | 是否展示为小红点 | boolean | false |
| max | 最大值,超过最大值会显示 {max}+,仅当 content 为数字时有效 | number | string | - |
| 名称 | 说明 |
|---|---|
| default | 徽标包裹的子元素 |
| content | 自定义徽标内容 |
组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制。
| 名称 | 默认值 | 描述 |
|---|---|---|
| @badge-size | 16px | - |
| @badge-color | @white | - |
| @badge-padding | 0 3px | - |
| @badge-font-size | @font-size-sm | - |
| @badge-font-weight | @font-weight-bold | - |
| @badge-border-width | @border-width-base | - |
| @badge-background-color | @red | - |
| @badge-dot-color | @red | - |
| @badge-dot-size | 8px | - |
| @badge-font-family | -apple-system-font, Helvetica Neue, Arial, sans-serif | - |
FAQs
### 介绍
The npm package @ophiuchus/badge receives a total of 2 weekly downloads. As such, @ophiuchus/badge popularity was classified as not popular.
We found that @ophiuchus/badge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.