Text Text
Display semantic text with emphasis, truncation and selection.
Import
Use <hui-text> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
vue
<template>
<view>
<hui-text type="primary" text="可选择的文本 / Selectable text" selectable @click="event0" />
<hui-text v-for="type in types" :key="type" :type="type">{{ type }}</hui-text
><hui-text bold>粗体 / Bold</hui-text><hui-text deleted>旧价 / Old price</hui-text
><hui-text underline>下划线 / Underline</hui-text
><hui-text :lines="1" custom-style="display:block;width:120px"
>一段会被截断的长文本 / A long truncated line</hui-text
>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const types = ['default', 'primary', 'success', 'warning', 'danger', 'info', 'secondary'] as const
const event0 = (arg0: unknown) => {
lastEvent.value = 'click' + ': ' + [describe(arg0)].join(', ')
}
</script>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
type | TextType | 'default' | Semantic type or input mode; see the type definition. |
size | ComponentSize | — | Component size; inherits configuration when omitted. |
bold | boolean | false | Use bold text. |
lines | number | — | Maximum displayed text lines. |
selectable | boolean | false | Allow selecting text. |
text | string | number | — | Display text; an explicit empty string suppresses fallback. |
deleted | boolean | false | Display strikethrough text. |
underline | boolean | false | Display underlined text. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
click | (event: unknown) | Emitted when the interactive area is clicked. |
Slots
| Slot | Parameters | Description |
|---|---|---|
prefix | — | Custom prefix region; replaces its fallback content. |
default | — | Main content. |
suffix | — | Custom suffix region; replaces its fallback content. |
Methods
None.
Types
TextProps、TextType、TextEmits are available from @nscode/handy-uni.
ts
export type TextType =
| 'default'
| 'primary'
| 'success'
| 'warning'
| 'danger'
| 'info'
| 'secondary'
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.