Link
Vue Router 的 RouterLink。能变色,能加前后图标。custom 我写死了,改不了。剩下的 HTML 属性走 $attrs。
Installation
pnpm dlx @weme-ui/weme-ui add linkUsage
Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import Link from '../link.vue'
</script>
<template>
<div class="flex flex-wrap gap-4 items-center">
<Link to="/" label="Documentation" />
</div>
</template>Examples
Colors
Vueexamples/colors.vueExpand codeHide code
<script lang="ts" setup>
import Link from '../link.vue'
</script>
<template>
<div class="flex flex-wrap gap-4 items-center">
<Link to="/" label="Default" color="default" />
<Link to="/" label="Accent" color="accent" />
<Link to="/" label="Neutral" color="neutral" />
<Link to="/" label="Info" color="info" />
<Link to="/" label="Success" color="success" />
<Link to="/" label="Warning" color="warning" />
<Link to="/" label="Error" color="error" />
</div>
</template>With Icon
Vueexamples/with-icon.vueExpand codeHide code
<script lang="ts" setup>
import Link from '../link.vue'
</script>
<template>
<div class="flex flex-wrap gap-4 items-center">
<Link to="/" label="With prefix" prefix-icon="ri:arrow-left-line" />
<Link to="/" label="With suffix" suffix-icon="ri:arrow-right-line" />
</div>
</template>External
Vueexamples/external.vueExpand codeHide code
<script lang="ts" setup>
import Link from '../link.vue'
</script>
<template>
<div class="flex flex-wrap gap-4 items-center">
<Link to="https://vuejs.org" label="Vue" />
<Link to="https://reka-ui.com" label="Reka UI" external-icon="ri:share-box-line" />
</div>
</template>Unstyled
Vueexamples/unstyled.vueExpand codeHide code
<script lang="ts" setup>
import Link from '../link.vue'
</script>
<template>
<div class="flex flex-wrap gap-4 items-center">
<Link to="/" label="Unstyled" unstyled />
</div>
</template>Props
PropTypeDefault
toRouteLocationRaw-
目标路由或 URL(Vue Router
RouterLink)RouteLocationRaw-replaceboolean-
使用
router.replace 而非 pushboolean-activeClassstring-
激活态 class
string-exactActiveClassstring-
精确激活态 class
string-ariaCurrentValue'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false''page'
精确激活时的
aria-current 值'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false''page'
viewTransitionboolean-
是否将导航 Promise 交给
document.startViewTransitionboolean-labelstring-
链接文案(无默认插槽内容时使用)
string-prefixIconIconifyIconProps['icon']-
前置图标(Iconify)
IconifyIconProps['icon']-
suffixIconIconifyIconProps['icon']-
后置图标(Iconify);传入时优先于
externalIconIconifyIconProps['icon']-
externalIconIconifyIconProps['icon']'ri:external-link-line'
外链后置图标(Iconify)
IconifyIconProps['icon']'ri:external-link-line'
hideExternalIconboolean-
是否隐藏后置 / 外链图标
boolean-color'default' | 'accent' | 'neutral' | 'info' | 'success' | 'warning' | 'error''default'
色彩
'default' | 'accent' | 'neutral' | 'info' | 'success' | 'warning' | 'error''default'
unstyledbooleanfalse
是否去掉默认表面样式
booleanfalseclassany-
根节点额外 class
any-uiPartial<LinkStyleSlots>-
覆盖 slots 样式(
root / prefixIcon / suffixIcon)Partial<LinkStyleSlots>-
Slots
SlotDescription
default自定义链接文案;未提供时回退到 label
自定义链接文案;未提供时回退到
labelAccessibility
最后还是原生 <a>(RouterLink 的 custom 插槽)。精确激活时可用 ariaCurrentValue 设 aria-current。
Keyboard Interactions
KeyDescription
Enter激活链接并导航
激活链接并导航
Files
src/components/link/link.vuesrc/components/link/link.props.tssrc/components/link/link.style.tssrc/components/link/link.uno.ts