Text
文本。

属性及支持度

微信小程序 H5 ReactNative 属性名 类型 默认值 说明
selectable Boolean false 文本是否可选
x space Boolean false 显示连续空格
x (true) decode Boolean false 是否解码
示例:
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Text } from '@tarojs/components'
  3. export default class PageView extends Component {
  4. constructor () {
  5. super(...arguments)
  6. this.state = {
  7. contents = []
  8. }
  9. }
  10. add = e => {
  11. const cot = this.state.contents
  12. cot.push({text: 'hello world'})
  13. this.setState(() => {
  14. return {contents: cot}
  15. })
  16. }
  17. remove = e => {
  18. const cot = this.state.contents
  19. cot.pop()
  20. this.setState(() => {
  21. return {contents: cot}
  22. })
  23. }
  24. render () {
  25. return (
  26. <View className="container">
  27. {this.state.contents.map(item => {
  28. return (
  29. <Text>{item.text}</Text>
  30. )
  31. })}
  32. <Button className="btn-max-w button_style" plain type="default" onClick={this.add}>add line</Button>
  33. <Button className="btn-max-w button_style" plain type="default" disabled={this.state.contents.length ? false:true} onClick={this.remove}>remove line</Button>
  34. </View>
  35. )
  36. }
  37. }