Link
A text hyperlink that can also act as a text-style action button without a destination.
Import
import { HuiLink } from '@nscode/handy-ui'
Basic Usage
With href, the component is a regular link that navigates when clicked. Without href, it acts as a text-style button.
<template>
<HuiSpace wrap>
<HuiLink href="https://example.com">Default link</HuiLink>
<HuiLink type="primary" href="https://example.com">Primary link</HuiLink>
<HuiLink type="primary">Without a destination</HuiLink>
</HuiSpace>
</template>
Types
type controls the color: default, primary, success, warning, danger, info, or help. The default type uses the text color and changes to the primary color on hover. Other types become lighter on hover and darker when pressed.
<template>
<HuiSpace wrap size="large">
<HuiLink href="https://example.com">Default(default)</HuiLink>
<HuiLink type="primary" href="https://example.com">Primary(primary)</HuiLink>
<HuiLink type="success" href="https://example.com">Success(success)</HuiLink>
<HuiLink type="warning" href="https://example.com">Warning(warning)</HuiLink>
<HuiLink type="danger" href="https://example.com">Danger(danger)</HuiLink>
<HuiLink type="info" href="https://example.com">Info(info)</HuiLink>
<HuiLink type="help" href="https://example.com">Help(help)</HuiLink>
</HuiSpace>
</template>
Underline
Set underline to hover (the default, visible on hover), always, or never. Boolean values are also accepted: true means hover, and false means never. Each row below demonstrates a value; hover over the links to compare them:
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap size="large">
<span class="row-label">hover</span>
<HuiLink href="https://example.com">Default</HuiLink>
<HuiLink type="primary" href="https://example.com">Primary</HuiLink>
<HuiLink type="danger" href="https://example.com">Danger</HuiLink>
</HuiSpace>
<HuiSpace wrap size="large">
<span class="row-label">always</span>
<HuiLink underline="always" href="https://example.com">Default</HuiLink>
<HuiLink type="primary" underline="always" href="https://example.com">Primary</HuiLink>
<HuiLink type="danger" underline="always" href="https://example.com">Danger</HuiLink>
</HuiSpace>
<HuiSpace wrap size="large">
<span class="row-label">never</span>
<HuiLink underline="never" href="https://example.com">Default</HuiLink>
<HuiLink type="primary" underline="never" href="https://example.com">Primary</HuiLink>
<HuiLink type="danger" underline="never" href="https://example.com">Danger</HuiLink>
</HuiSpace>
<HuiSpace wrap size="large">
<span class="row-label">true</span>
<HuiLink :underline="true" href="https://example.com">Equivalent to hover</HuiLink>
<span class="row-label">false</span>
<HuiLink :underline="false" href="https://example.com">Equivalent to never</HuiLink>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Disabled State
A disabled link is dimmed and its href is removed. Clicking neither navigates nor emits click, and the link is excluded from Tab navigation. Every type has a disabled appearance.
<template>
<HuiSpace wrap size="large">
<HuiLink disabled href="https://example.com">Default</HuiLink>
<HuiLink type="primary" disabled href="https://example.com">Primary</HuiLink>
<HuiLink type="success" disabled href="https://example.com">Success</HuiLink>
<HuiLink type="warning" disabled href="https://example.com">Warning</HuiLink>
<HuiLink type="danger" disabled href="https://example.com">Danger</HuiLink>
<HuiLink type="info" disabled href="https://example.com">Info</HuiLink>
<HuiLink type="help" disabled href="https://example.com">Help</HuiLink>
<HuiLink type="primary" icon="edit" disabled>With an icon</HuiLink>
</HuiSpace>
</template>
Icons
Pass an icon name to icon to display it before the text. Its color follows the link.
<template>
<HuiSpace wrap size="large">
<HuiLink icon="search" type="primary">Search</HuiLink>
<HuiLink icon="edit" type="primary">Edit</HuiLink>
<HuiLink icon="download" type="success" href="https://example.com">Download</HuiLink>
<HuiLink icon="trash" type="danger">Delete</HuiLink>
<HuiLink icon="link" href="https://example.com" underline="always">View the original</HuiLink>
</HuiSpace>
</template>
Navigation Targets
target is the native navigation target. With target="_blank", the component adds rel="noopener noreferrer" automatically; an explicit rel takes precedence. Other native attributes, such as download, are forwarded to <a>.
<template>
<HuiSpace wrap size="large">
<HuiLink type="primary" href="https://example.com" target="_blank"
>Open in a new window (_blank)</HuiLink
>
<HuiLink type="primary" href="https://example.com" target="_self"
>Open in the current window (_self)</HuiLink
>
<HuiLink type="primary" href="https://example.com" target="_blank" rel="noopener">
Custom rel
</HuiLink>
</HuiSpace>
</template>
Inline Links
The link inherits the surrounding font size and line height, so it can be placed directly within a paragraph.
<template>
<p style="margin: 0; line-height: 1.8">
Before submitting, read
<HuiLink type="primary" href="https://example.com" target="_blank">Terms of Service</HuiLink>
and <HuiLink type="primary" href="https://example.com" target="_blank">Privacy Policy</HuiLink>.
If you have questions, <HuiLink type="primary" underline="always">contact support</HuiLink>.
</p>
</template>
Action Links
Without href, the component acts as a button with role="button" and tabindex="0". It can receive Tab focus, and Enter or Space triggers click.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiLink, HuiMessage, HuiSpace } from '@nscode/handy-ui'
const count = ref(0)
const edit = () => {
count.value += 1
HuiMessage.info('Edit clicked')
}
const remove = () => {
count.value += 1
HuiMessage.warning('Delete clicked')
}
</script>
<template>
<HuiSpace wrap size="large">
<HuiLink type="primary" icon="edit" @click="edit">Edit</HuiLink>
<HuiLink type="danger" icon="trash" @click="remove">Delete</HuiLink>
<HuiLink type="primary" disabled @click="edit">Disabled: no event</HuiLink>
</HuiSpace>
<p style="margin-top: 12px">click emitted {{ count }} times</p>
</template>
Props
| Prop | Type | Default value | Description |
|---|---|---|---|
| type | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'help' | 'default' | 'default' | Type (color) |
| underline | boolean | 'always' | 'hover' | 'never' | 'hover' | Underline display mode |
| disabled | boolean | false | Disabled |
| href | string | — | Destination URL; acts as a button when omitted |
| target | string | — | Native target |
| icon | string | — | Icon name before the text; see the Icon component |
Events
| Event | Parameters | Description |
|---|---|---|
| click | (event: MouseEvent) | Emitted on click, except when disabled |
Slots
| Slot | Description |
|---|---|
| default | Link text |
Types
import type { LinkProps, LinkType, LinkUnderline } from '@nscode/handy-ui'