Link 链接
用于页面跳转或轻量动作,适合在正文、列表和操作区中承载低重量入口。
何时使用
- 在正文、详情页或表格操作区放置低强调的跳转入口。
- 用状态色表达成功、警告、危险等轻量动作。
- 需要在链接前展示默认图标、业务图标或加载反馈。
基础用法
vue
<template>
<x-link href="https://example.com">文本链接</x-link>
<x-link href="https://example.com/docs" strong>强调链接</x-link>
<x-link disabled>禁用链接</x-link>
</template>链接状态
vue
<template>
<x-link href="https://example.com">普通链接</x-link>
<x-link status="success" href="https://example.com">成功链接</x-link>
<x-link status="warning" href="https://example.com">警告链接</x-link>
<x-link status="danger" href="https://example.com">危险链接</x-link>
</template>悬浮底色
vue
<template>
<x-link href="https://example.com">默认悬浮底色</x-link>
<x-link href="https://example.com" :hoverable="false">无悬浮底色</x-link>
<x-link status="danger" href="https://example.com" :hoverable="false">危险无底色</x-link>
</template>图标与插槽
vue
<template>
<x-link icon href="https://example.com">默认图标</x-link>
<x-link href="https://example.com">
<template #icon>
<span aria-hidden="true">#</span>
</template>
自定义图标
</x-link>
<x-link icon disabled>禁用图标</x-link>
</template>加载与事件
vue
<template>
<x-link :loading="loading" @click="runLoading">异步加载</x-link>
<x-link @click="pushLog('normal')">点击计数</x-link>
<x-link disabled @click="pushLog('disabled')">禁用不触发</x-link>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const loading = ref(false);
const logs = ref<string[]>([]);
const runLoading = () => {
loading.value = true;
logs.value = ['loading link clicked', ...logs.value];
window.setTimeout(() => {
loading.value = false;
}, 1600);
};
const pushLog = (label: string) => {
logs.value = [`${label} clicked`, ...logs.value];
};
</script>没有传入 href 时,Link 会作为轻量动作入口处理,可通过键盘聚焦并使用 Enter 或 Space 触发点击事件。
原生链接属性
vue
<template>
<x-link
href="https://example.com"
target="_blank"
rel="noopener noreferrer"
aria-label="在新窗口打开示例站点"
>
新窗口外链
</x-link>
<x-link href="/files/report.pdf" download>下载链接</x-link>
</template>target、rel、download、aria-*、id、class、style 等原生 <a> 属性会透传到根节点。使用 target="_blank" 时建议同时设置 rel="noopener noreferrer"。
按需导入
ts
import { Link } from 'x-next';Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
href | 链接地址 | string | - |
status | 链接状态 | 'normal' | 'warning' | 'success' | 'danger' | 'normal' |
hoverable | 鼠标悬浮时是否展示底色 | boolean | true |
icon | 是否显示默认图标 | boolean | false |
loading | 是否为加载状态,加载中不会触发点击事件 | boolean | false |
disabled | 是否禁用,禁用时不会触发点击事件 | boolean | false |
strong | 是否加粗,x-next 扩展能力 | boolean | false |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
click | 点击链接或通过键盘触发动作链接时触发,禁用或加载中不会触发 | event: MouseEvent | KeyboardEvent |
Slots
| 插槽名 | 说明 |
|---|---|
default | 链接文本 |
icon | 自定义图标 |