這篇文章給大家分享的是有關(guān)如何解決微信小程序中textarea層級(jí)過(guò)高的問(wèn)題的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
創(chuàng)新互聯(lián)公司是專業(yè)的潼關(guān)網(wǎng)站建設(shè)公司,潼關(guān)接單;提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行潼關(guān)網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
建立一個(gè)新的textarea 組件代替原生textarea ,上代碼
<template> <view class="ui-textarea"> <textarea class="textarea {{ hide? 'hidden':''}}" auto-height maxlength="{{maxlength}}" name="{{ name }}" value="{{ txt }}" placeholder="{{ placeholder }}" bindinput="onInput" bindblur="onBlur" focus="{{focus}}"></textarea> <view hidden="{{ hide == false }}" class="{{ txt === ''?'text placeholder':'text'}}" bindtap="onFocus">{{ txt ===''? placeholder:txt }}</view> </view> </template> <script> export default { config: { usingComponents: {} }, behaviors: [], properties: { placeholder: { type: String, value: '' }, maxlength: { type: Number, value: 128 }, name: String, value: { type: String, value: '' } }, data: { hide: true, txt: '', focus: false }, ready() { if (this.data.value != '') { this.setData({ txt: this.data.value }) } }, methods: { onFocus() { this.setData({ hide: false, focus: true }) }, onInput(e) { this.setData({ txt: e.detail.value }) }, onBlur() { this.setData({ hide: true, focus: false }) } } } </script> <style lang="less"> .ui-textarea { position: relative !important; .textarea.hidden { display: block !important; position: absolute !important; left: -999px; right: -999px; top: 0; } .textarea { width: 100%; box-sizing: border-box; } .text { height: 100%; padding: 6px 5px; font-size: 14px; } .placeholder { color: #888; } } </style>
Vue 代碼,自己根據(jù)需求改一下 ,特別注意,不要用 wx;if 或者 hidden 屬性 , wx:if 頻繁渲染,雖然可以用,hidden 會(huì)出現(xiàn) 部分顯示bug,[hidden] 會(huì)使auto-height 首次不正確
感謝各位的閱讀!關(guān)于“如何解決微信小程序中textarea層級(jí)過(guò)高的問(wèn)題”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
文章標(biāo)題:如何解決微信小程序中textarea層級(jí)過(guò)高的問(wèn)題
標(biāo)題URL:http://chinadenli.net/article36/geojsg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、網(wǎng)站設(shè)計(jì)、面包屑導(dǎo)航、網(wǎng)站改版、品牌網(wǎng)站制作、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)