经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » 微信小程序 » 查看文章
微信小程序 textarea 层级过高问题简单解决方案
来源:jb51  时间:2019/10/14 12:24:13  对本文有异议

这篇文章主要介绍了微信小程序 textarea 层级过高问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

建立一个新的textarea 组件代替原生textarea ,废话不多说,上代码

  1. <template>
  2. <view class="ui-textarea">
  3. <textarea class="textarea {{ hide? 'hidden':''}}" auto-height maxlength="{{maxlength}}" name="{{ name }}" value="{{ txt }}" placeholder="{{ placeholder }}" bindinput="onInput" bindblur="onBlur" focus="{{focus}}"></textarea>
  4. <view hidden="{{ hide == false }}" class="{{ txt === ''?'text placeholder':'text'}}" bindtap="onFocus">{{ txt ===''? placeholder:txt }}</view>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. config: {
  10. usingComponents: {}
  11. },
  12. behaviors: [],
  13. properties: {
  14. placeholder: {
  15. type: String,
  16. value: ''
  17. },
  18. maxlength: {
  19. type: Number,
  20. value: 128
  21. },
  22. name: String,
  23. value: {
  24. type: String,
  25. value: ''
  26. }
  27. },
  28. data: {
  29. hide: true,
  30. txt: '',
  31. focus: false
  32. },
  33. ready() {
  34. if (this.data.value != '') {
  35. this.setData({ txt: this.data.value })
  36. }
  37. },
  38. methods: {
  39. onFocus() {
  40. this.setData({ hide: false, focus: true })
  41. },
  42. onInput(e) {
  43. this.setData({ txt: e.detail.value })
  44. },
  45. onBlur() {
  46. this.setData({ hide: true, focus: false })
  47. }
  48. }
  49. }
  50. </script>
  51. <style lang="less">
  52. .ui-textarea {
  53. position: relative !important;
  54.  
  55. .textarea.hidden {
  56. display: block !important;
  57. position: absolute !important;
  58. left: -999px;
  59. right: -999px;
  60. top: 0;
  61. }
  62.  
  63. .textarea {
  64. width: 100%;
  65. box-sizing: border-box;
  66. }
  67.  
  68. .text {
  69. height: 100%;
  70. padding: 6px 5px;
  71. font-size: 14px;
  72. }
  73.  
  74. .placeholder {
  75. color: #888;
  76. }
  77. }
  78. </style>

Vue 代码,自己根据需求改一下 ,特别注意,不要用 wx;if 或者 hidden 属性 , wx:if 频繁渲染,虽然可以用,hidden 会出现 部分显示bug,[hidden] 会使auto-height 首次不正确

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号