关于微信小程序textarea层级过高问题解决
一、前言
相信做过微信小程序开发的人应该都碰到过这个问题,因为这个需求实在太常见了
由于textarea是属于原生组件,层级最高,不管在页面中我们设置z-index值多少都会被textarea组件遮挡住,很影响用户体验,
目前官方对该问题还没有修复,当然官方也给出了解决该问题的其他方案,使用cover-view和 cover-image替代,但个人感觉并不是很好,有一些限制
二、使用场景及解决方案
1、弹窗显示
2、底部fixed定位的按钮,页面滚动时,例如添加购物车,显示价格
针对以上两种业务场景解决方式不同
针对场景1弹窗显示的处理方式
在显示弹窗时通过if或者绑定class属性将textarea组件隐藏,弹窗关闭时显示,如下
<div class="section" :class="isShowInput?'':'hidden'">
<textarea class="content" placeholder="输入内容" v-model="userInfo"></textarea>
</div>
针对场景2(滚动)如何解决
我们在输入时使用textarea组件,不输入的时候text来显示文字和placeholder,这样我们需要单独设置几个标签
<textarea>输入内容</textarea>
<scroll-view>用于显示文本内容</scroll-view>
<div class="placeholder" v-if="!content">说说对这个活动看法吧</div>
通过v-show来显示或隐藏该组件,使用scroll-view标签为文本内容设置可滚动,这里设置了isFocus聚焦,通过按钮的形式去触发textaare的Focus
完整代码如下:
<textarea
v-model="content"
@blur="bindContentBlur"
v-show="isInputContentFocus"
placeholder="说说对这个活动看法吧"
v-bind:focus="isFocus"
></textarea>
<scroll-view
scroll-y
class="content"
v-text="content"
@click="bindContentFocus"
v-show="isContentFocus"
>
<div class="placeholder" v-if="!content">说说对这个活动看法吧</div>
</scroll-view>
data() {
return {
isContentFocus: true,
isInputContentFocus: false,
isFocus: false
};
},
methods: {
bindContentFocus(e) {
this.isFocus = true; //触发焦点
this.isContentFocus = false; //聚焦时隐藏内容文本标签
this.isInputContentFocus = true;
console.log("Focus isFocus", this.isFocus);
},
bindContentBlur(e) {
this.isContentFocus = true; //聚焦时隐藏内容文本标签
this.isInputContentFocus = false;
this.isFocus = false; //失去焦点
console.log("Blur isFocus", this.isFocus);
}
}
三、其他方式
官方给出了针对textarea的解决方式,使用cover-view和 cover-image替代,这两个组件也是原生组件,可以覆盖textarea组件
<cover-view class="btn-save">
<button
class="btn btn-love btn-apply"
@click="apply"
:disabled="apply_status"
v-text="apply_status?'我已报名':'我要报名'"
></button>
</cover-view>
不过这里有个限制就是<cover-view/> 内只能嵌套 <cover-view/> <cover-image/> <button/> <navigator/>组件,view 标签的子节点树在真机上都会被忽略。
像上面场景2的需求,添加购物车,显示价格,很明显这种方式并不适用,当然如果底部我们只有一个button的话是可以使用这种方式去解决的
参考阅读
https://blog.csdn.net/huobox/article/details/84859712
https://1c7.me/2018-10-30-wechat-mini-program-textarea-z-index-problem/
关于微信小程序textarea层级过高问题解决的更多相关文章
- 解决微信小程序textarea层级太高遮挡其他组件的问题
<view class='remark'> <view class='title'> 备注说明 </view> <textarea class='mark_t ...
- 微信小程序textarea层级过高(盖住其他元素)
根据官方文档,textarea 是原生组件 (https://developers.weixin.qq.com/miniprogram/dev/component/textarea.html),所谓原 ...
- 微信小程序 textarea 层级过高的解决方式
建立一个新的textarea 组件代替原生textarea ,废话不多说,上代码 <template> <view class="ui-textarea"> ...
- 微信小程序echarts层级太高
项目中因为需求,底部的tab导航栏是自己写的,在开发者工具中一切正常:但是在真机上页面滑动时,echarts的层级比tab高,调过两者的z-index后仍然如此. 经过查找后发现cover-view和 ...
- 微信小程序 textarea的placeholder层级过高 在弹层之上 bug解决方法
微信小程序textarea的placeholder的层级一直都是一个神坑, 我们是没有办法将我们的弹层加大层级去盖过placeholder的, 所以要解决这个问题只能从另外的角度找思路 我的思路是 : ...
- 微信小程序 textarea 简易解决方案
微信小程序中textarea没有bindchange事件,所以无法在输入时给变量赋值. 虽然可以使用bindblur事件,但是绑定bindblur事件,如果再点击按钮,则先执行完按钮事件后,再去执行b ...
- 解决微信小程序textarea 里输入的文字或者是placeholder里的值,飘到弹出view上
在uniapp微信小程序开发中使用textarea,结果发现输入框的问题浮动起来,view无法把他覆盖,设法设置index的值也不生效,所以只能是通过条件v-if或者v-show使其隐藏就可以了
- 绑定bindchange事件的微信小程序swiper闪烁,抖动问题解决,(将微信小程序切换到后台一段时间,再打开微信小程序,会出现疯狂循环轮播,造成抖动现象)
微信小程序开发文档-组件-swiper后面追加的新闻如上图所示: 如果在bindchange事件给swiper的current属性对应的值{{current}}赋值,就会造成抖动现象. bindcha ...
- 微信小程序textarea组件在fixed定位中随页面滚动
如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true https://developers.weixin.qq.com/miniprogr ...
随机推荐
- Win 10 Revit 2019 安装过程,亲自踩的一遍坑,有你想要的细节
首先就是安装吖,不管是管理员权限还是普通权限,都是以下这个问题,跟权限没关系 failed to load .....revitcontentpackui.dll (126) 尝试了网上能查到的各种方 ...
- [LeetCode] Inorder Successor in BST II 二叉搜索树中的中序后继节点之二
Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Th ...
- JAVA 热文
Java技术面试篇 Javase基础面试题(1) Javase基础面试题(2) Javase基础面试题(3) Javase基础面试题(4) Javase基础面试题(5) Javaweb面试题(6) J ...
- 谈一谈从 Delphi 2009 之后就支援的重要功能 – 泛型 (Generic)
前言 在C++的语言基础当中,除了物件导向.事件驱动的概念之外,模版设计(Template)也是非常重要的一环.然而,C++的开发人员能够善用模版设计的并不多.模版设计这个好物,一般还有一个名称,就是 ...
- c# 钩子类
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...
- C语言面试题分类->回调
本文主要讲解如果实现回调,特别是在封装接口的时候,回调显得特别重要,我们首先假设有两个程序员在写代码,A程序员写底层驱动接口,B程序员写上层应用程序,然而此时底层驱动接口A有一个数据d需要传输给B,此 ...
- Python爬虫6-利用ProxyHandler设置代理服务器
GitHub代码练习地址:https://github.com/Neo-ML/PythonPractice/blob/master/SpiderPrac09_ProxyHandler.pyProxyH ...
- [Swift]LeetCode68. 文本左右对齐 | Text Justification
Given an array of words and a width maxWidth, format the text such that each line has exactly maxWid ...
- [Swift]LeetCode90. 子集 II | Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the ...
- [Swift]LeetCode371. 两整数之和 | Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...