微信小程序官方組件展示之基礎(chǔ)內(nèi)容text源碼

以下將展示微信小程序之基礎(chǔ)內(nèi)容text源碼官方組件能力,組件樣式僅供參考,開發(fā)者可根據(jù)自身需求定義組件樣式,具體屬性參數(shù)詳見小程序開發(fā)文檔。

功能描述:

文本。

屬性說明:

WebView

Skyline

組件差異

- 內(nèi)聯(lián)文本只能用 text 組件,不能用 view,如 foobar


Bug& Tip

1.tip:decode可以解析的有? < > & '

2.tip:各個操作系統(tǒng)的空格標準并不一致。

3.tip:text組件內(nèi)只支持 text嵌套。

4.tip:除了文本節(jié)點以外的其他節(jié)點都無法長按選中。

5.bug:基礎(chǔ)庫版本低于2.1.0 時, text 組件內(nèi)嵌的 text style 設置可能不會生效。

示例代碼:

JAVASCRIPT

const texts = [

? '2011年1月,微信1.0發(fā)布',

? '同年5月,微信2.0語音對講發(fā)布',

? '10月,微信3.0新增搖一搖功能',

? '2012年3月,微信用戶突破1億',

? '4月份,微信4.0朋友圈發(fā)布',

? '同年7月,微信4.2發(fā)布公眾平臺',

? '2013年8月,微信5.0發(fā)布微信支付',

? '2014年9月,企業(yè)號發(fā)布',

? '同月,發(fā)布微信卡包',

? '2015年1月,微信第一條朋友圈廣告',

? '2016年1月,企業(yè)微信發(fā)布',

? '2017年1月,小程序發(fā)布',

? '......'

]

Page({

? onShareAppMessage() {

? ? return {

? ? ? title: 'text',

? ? ? path: 'page/component/pages/text/text'

? ? }

? },

? data: {

? ? text: '',

? ? canAdd: true,

? ? canRemove: false

? },

? extraLine: [],

? add() {

? ? this.extraLine.push(texts[this.extraLine.length % 12])

? ? this.setData({

? ? ? text: this.extraLine.join('\n'),

? ? ? canAdd: this.extraLine.length < 12,

? ? ? canRemove: this.extraLine.length > 0

? ? })

? ? setTimeout(() => {

? ? ? this.setData({

? ? ? ? scrollTop: 99999

? ? ? })

? ? }, 0)

? },

? remove() {

? ? if (this.extraLine.length > 0) {

? ? ? this.extraLine.pop()

? ? ? this.setData({

? ? ? ? text: this.extraLine.join('\n'),

? ? ? ? canAdd: this.extraLine.length < 12,

? ? ? ? canRemove: this.extraLine.length > 0,

? ? ? })

? ? }

? ? setTimeout(() => {

? ? ? this.setData({

? ? ? ? scrollTop: 99999

? ? ? })

? ? }, 0)

? }

})

WXML

<view class="container">

? <view class="page-body">

? ? <view class="page-section page-section-spacing">

? ? ? <view class="text-box" scroll-y="true" scroll-top="{{scrollTop}}">

? ? ? ? <text>{{text}}</text>

? ? ? </view>

? ? ? <button disabled="{{!canAdd}}" bindtap="add">add line</button>

? ? ? <button disabled="{{!canRemove}}" bindtap="remove">remove line</button>

? ? </view>

? </view>

</view>


版權(quán)聲明:本站所有內(nèi)容均由互聯(lián)網(wǎng)收集整理、上傳,如涉及版權(quán)問題,請聯(lián)系我們第一時間處理。

原文鏈接地址:https://developers.weixin.qq.com/miniprogram/dev/component/text.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容