Skip to content

Highlight 高亮文本

介绍

高亮指定文本内容。

引入

js
import { createApp } from 'vue';
import { Highlight } from '@szhn/dh-design-mobile';

const app = createApp();
app.use(Highlight);

代码演示

基础用法

通过 source-string 指定源文本内容,通过 keywords 指定需要高亮的关键字。

html
<van-highlight :source-string="text" keywords="难题" />

多字符匹配

如果需要指定多个关键字,可以以数组的形式传入 keywords

html
<van-highlight :source-string="text" :keywords="['难题', '终有一天', '答案']" />

设置高亮标签类名

通过 highlight-class 可以设置高亮标签的类名。

html
<van-highlight :source-string="text" keywords="生活" highlight-class="custom-class" />

API

Props

参数说明类型默认值
auto-escape是否自动转义booleantrue
case-sensitive是否区分大小写booleanfalse
highlight-class高亮元素的类名string-
highlight-tag高亮元素对应的 HTML 标签名stringspan
keywords期望高亮的文本string | string[]-
source-string源文本string-
tag根节点对应的 HTML 标签名stringdiv
unhighlight-class非高亮元素的类名string-
unhighlight-tag非高亮元素对应的 HTML 标签名stringspan

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件。

名称默认值描述
--van-highlight-tag-colorvar(--van-primary-color)高亮文本颜色