小程序textarea穿透问题解决方案

前段时间做个小程序项目,遇到textarea层级过高穿透的问题。社区也没有找到合适的解决方案,无奈在textarea的基础上重新写了个组件。
解决思路:将textarea的值写入一个view里面,用view模拟一个textarea,当点击输入时(获得焦点)把view替换成为textarea,失去焦点时获取值显示为view。

wxml代码:

<view class="text_area_view">
    <view bindtap='handleFocus' wx:if="{{hidden == true}}" style="{{textareaVal? '':placeholderStyle}}" class="text_view">{{textareaVal?textareaVal: placeholder}}</view>
    <view wx:if="{{hidden == false}}">
        <textarea placeholder='{{placeholder}}' auto-height value='{{textareaVal}}' fixed='true' bindinput='textarea' focus="{{focus}}" bindblur="leaveFocus"  maxlength="{{maxlength}}" placeholder-style="{{placeholderStyle}}"></textarea>
    </view>
</view>

js代码:

	handleFocus: function () {
			this.setData({
				hidden: false,
				Focus:true
			})
		},
		leaveFocus(e){
			this.setData({
				hidden: true,
				Focus: true,
				textareaVal: this.data.content,
			})
		},
		textarea: function (e) {
			this.setData({
				content: e.detail.value
			})
			this.triggerEvent('change', e.detail.value)
		},

点击查看完整的案例https://github.com/tony-xf/text-area-demo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值