1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-09-12 16:40:40 +08:00
Files
uni-halo/.agents/bak-skills/uniappx-project/references/components/built-in/text.md
T
2026-08-31 07:58:23 +08:00

3.9 KiB
Raw Blame History

text

Instructions

文本组件。用于包裹文本内容。

在app-uvue和app-nvue中,文本只能写在text中,而不能写在view的text区域。

虽然app-uvue中写在view的text区域的文字,也会被编译器自动包裹一层text组件,看起来也可以使用。但这样会造成无法修改该text文字的样式,详见uvue的 样式不继承 章节

Syntax

  • 使用 <text />(或 <text></text>,当需要包裹子节点时)。
  • 遇到平台差异时,建议使用条件编译(#ifdef / #endif)显式处理。

Properties

属性名 类型 默认值 说明 平台差异说明
selectable Boolean false 文本是否可选 小红书小程序不支持
user-select Boolean false 文本是否可选 微信小程序
space String 显示连续空格 钉钉小程序不支持
decode Boolean false 是否解码 百度、钉钉小程序不支持

Events

See official docs for full events list: https://doc.dcloud.net.cn/uni-app-x/component/text.html

Platform Compatibility

See official docs for platform support table: https://doc.dcloud.net.cn/uni-app-x/component/text.html

Examples

Example (Example 1)

<!-- 本示例未包含完整css获取外链css请参考上文在hello uni-app项目中查看 -->
<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt">
			<view class="text-box" scroll-y="true">
				<text>{{text}}</text>
			</view>
			<view class="uni-btn-v">
				<button type="primary" :disabled="!canAdd" @click="add">add line</button>
				<button type="warn" :disabled="!canRemove" @click="remove">remove line</button>
			</view>
		</view>
	</view>
</template>

Example (Example 2)

<!-- 本示例未包含完整css获取外链css请参考上文在hello uni-app项目中查看 -->
<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt">
			<view class="text-box" scroll-y="true">
				<text>{{text}}</text>
			</view>
			<view class="uni-btn-v">
				<button type="primary" :disabled="!canAdd" @click="add">add line</button>
				<button type="warn" :disabled="!canRemove" @click="remove">remove line</button>
			</view>
		</view>
	</view>
</template>

Example (Example 3)

<script>
export default {
    data() {
        return {
            texts: [
                'HBuilder900万开发者选择的IDE',
                'MUI,轻巧、漂亮的前端开源框架',
                'wap2appM站快速转换原生体验的App',
                '5+Runtime,为HTML5插上原生的翅膀',
                'HBuilderX,轻巧、极速,极客编辑器',
                'uni-app,终极跨平台方案',
                'HBuilder900万开发者选择的IDE',
                'MUI,轻巧、漂亮的前端开源框架',
                'wap2appM站快速转换原生体验的App',
                '5+Runtime,为HTML5插上原生的翅膀',
                'HBuilderX,轻巧、极速,极客编辑器',
                'uni-app,终极跨平台方案',
                '......'
            ],
            text: '',
            canAdd: true,
            canRemove: false,
            extraLine: []
        }
    },
    methods: {
        add: function(e) {
            this.extraLine.push(this.texts[this.extraLine.length % 12]);
            this.text = this.extraLine.join('\n');
            this.canAdd = this.extraLine.length < 12;
            this.canRemove = this.extraLine.length > 0;
        },
        remove: function(e) {
            if (this.extraLine.length > 0) {
                this.extraLine.pop();
                this.text = this.extraLine.join('\n');
                this.canAdd = this.extraLine.length < 12;
                this.canRemove = this.extraLine.length > 0;
            }
        }
    }
}
</script>

Reference: Official Documentation