Icon Icon
Render registered icons or image sources with an accessible label.
Import
Use <hui-icon> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
<template>
<view>
<hui-icon name="search" label="搜索 / Search" :size="28" @click="event0" />
<hui-icon name="check" :size="20" /><hui-icon
name="close"
color="var(--hui-color-danger)"
/><hui-icon name="loading" spin />
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const event0 = (arg0: unknown) => {
lastEvent.value = 'click' + ': ' + [describe(arg0)].join(', ')
}
</script>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | — | Item identifier or registered icon name. |
src | string | — | Image URL. |
size | string | number | — | Component size; inherits configuration when omitted. |
color | string | — | Color override; prefer theme variables. |
spin | boolean | false | Continuously rotate the icon. |
label | string | — | Visible label. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
click | (event: unknown) | Emitted when the interactive area is clicked. |
Slots
None.
Methods
None.
Register a custom icon
registerIcon(name, svg) accepts a complete SVG string, then exposes it through the name prop. Registering the same name replaces the previous icon and clears its cached URI. Register trusted static SVG content.
import { registerIcon } from '@nscode/handy-uni'
registerIcon(
'business-check',
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" d="m5 12 4 4 10-10"/></svg>'
)
Types
IconProps、IconEmits are available from @nscode/handy-uni.
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.