WeChat Open Platform

Mini Programs Documentation

text

Text

Attribute name Type Default value Description Minimum version
selectable Boolean false Whether text is selectable {%version('1.1.0')%}

Supports the escape character "\".

<text/> nesting is only supported in the <text/> component.

Apart from text nodes, all other nodes are unable to be selected by being pressed and held.

Example:

<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')
      })
    }
  }
})

text

Bugs & Tips

  1. tip: The text press and hold copy function has still not been implemented.