|
1 | 1 | # Built-in Components
|
2 | 2 |
|
| 3 | +## AutoLink |
| 4 | + |
| 5 | +- Props: |
| 6 | + |
| 7 | + - config |
| 8 | + - Type: `AutoLinkConfig` |
| 9 | + - Required: `true` |
| 10 | + |
| 11 | +```ts |
| 12 | +interface AutoLinkConfig { |
| 13 | + /** |
| 14 | + * Pattern to determine if the link should be active, which has higher priority than `exact` |
| 15 | + */ |
| 16 | + activeMatch?: string | RegExp |
| 17 | + |
| 18 | + /** |
| 19 | + * The `aria-label` attribute |
| 20 | + */ |
| 21 | + ariaLabel?: string |
| 22 | + |
| 23 | + /** |
| 24 | + * Whether the link should be active only if the url is an exact match |
| 25 | + */ |
| 26 | + exact?: boolean |
| 27 | + |
| 28 | + /** |
| 29 | + * URL of the auto link |
| 30 | + */ |
| 31 | + link: string |
| 32 | + |
| 33 | + /** |
| 34 | + * The `rel` attribute |
| 35 | + */ |
| 36 | + rel?: string |
| 37 | + |
| 38 | + /** |
| 39 | + * The `target` attribute |
| 40 | + */ |
| 41 | + target?: string |
| 42 | + |
| 43 | + /** |
| 44 | + * Text of the auto link |
| 45 | + */ |
| 46 | + text: string |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +- Usage: |
| 51 | + |
| 52 | +```md |
| 53 | +<AutoLink :config="autoLinkConfig" /> |
| 54 | + |
| 55 | +<AutoLink :config="autoLinkConfig"> |
| 56 | + default slot |
| 57 | +</AutoLink> |
| 58 | + |
| 59 | +<AutoLink :config="autoLinkConfig"> |
| 60 | + <template #before>before slot</template> |
| 61 | + <template #after>after slot</template> |
| 62 | +</AutoLink> |
| 63 | + |
| 64 | +<AutoLink :config="autoLinkConfig"> |
| 65 | + <template v-slot="config">{{ config.text }}</template> |
| 66 | +</AutoLink> |
| 67 | + |
| 68 | +<AutoLink :config="autoLinkConfig"> |
| 69 | + <template #before="config">{{ config.text }}</template> |
| 70 | +</AutoLink> |
| 71 | +``` |
| 72 | + |
| 73 | +- Details: |
| 74 | + |
| 75 | + This component will automatically render internal link as `<RouteLink>`, and render external link as `<a>`. It will also add necessary attributes correspondingly. |
| 76 | + |
| 77 | + You can make use of the `before` and `after` slots to render content before and after the text. Also, you can use the `default` slot to render the text (default text is `config.text`). |
| 78 | + |
| 79 | + This component is mainly for developing themes. Users won't need it in most cases. For theme authors, it's recommended to use this component to render links that could be either internal or external. |
| 80 | + |
3 | 81 | ## ClientOnly
|
4 | 82 |
|
5 | 83 | - Usage:
|
|
73 | 151 |
|
74 | 152 | If the `active` prop is set to `true`, the link will have an extra `activeClass`. Notice that the active status won't be updated automatically when the route changes.
|
75 | 153 |
|
76 |
| - This component is mainly for developing themes. You won't need it in most cases. For theme authors, it's recommended to use this component instead of the `<RouterLink>` component from `vue-router`. |
| 154 | + This component is mainly for developing themes. Users won't need it in most cases. For theme authors, it's recommended to use this component to render internal links instead of the `<RouterLink>` component from `vue-router`. |
0 commit comments