跳到主要内容
版本:1.x

Text

文本

属性

属性名类型默认值说明
selectableBooleanfalse文本是否可选
spaceBooleanfalse显示连续空格
decodeBooleanfalse是否解码

各端支持度

属性微信小程序H5ReactNative百度小程序支付宝小程序抖音小程序
selectable
space
decode
示例:
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'

export default class PageView extends Component {
state = {
contents: [],
contentsLen: 0
}

add = () => {
this.setState(prev => {
const cot = prev.contents.slice()
cot.push({ text: 'hello world' })
return {
contents: cot,
contentsLen: cot.length
}
})
}

remove = () => {
this.setState(prev => {
const cot = prev.contents.slice()
cot.pop()
return {
contents: cot,
contentsLen: cot.length
}
})
}

render () {
return (
<View className='container'>
{this.state.contents.map((item, index) => (
<Text key={index}>{item.text}</Text>
))}
<Button className='btn-max-w button_style' plain type='default' onClick={this.add}>add line</Button>
<Button className='btn-max-w button_style' plain type='default' disabled={this.state.contentsLen ? false : true} onClick={this.remove}>remove line</Button>
</View>
)
}
}