Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program content component text (text)


May 18, 2021 WeChat Mini Program Development Document


Table of contents


text

Text.
The property name Type The default Description The lowest version
selectable Boolean false Whether the text is optional 1.1.0
space String false Displays consecutive spaces 1.4.0
decode Boolean false Whether to decode 1.4.0

Space valid value:

Value Description
ensp Chinese is half the size of a character space
emsp Chinese character space size
nbsp The space size that is set according to the font
Tips
  • Decode can be   < > & '    
  • Space standards are not consistent across operating systems.
  • <text/> only supported within the <text/> component.
  • No node other than the text node can be long-pressed and selected.

Example:

Code snippets

<view class="btn-area">
  <view class="body-view">
    <text>{{text}}</text>
    <button bindtap="add">add line</button>
    <button bindtap="remove">remove line</button>
  </view>
</view>
var initData = 'this is first line\nthis is second line'
var extraLine = [];
Page({
  data: {
    text: initData
  },
  add: function(e) {
    extraLine.push('other line')
    this.setData({
      text: initData + '\n' + extraLine.join('\n')
    })
  },
  remove: function(e) {
    if (extraLine.length > 0) {
      extraLine.pop()
      this.setData({
        text: initData + '\n' + extraLine.join('\n')
      })
    }
  }
})


WeChat small program content component text (text)