欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序vant?輸入框問題處理方案

 更新時(shí)間:2023年09月08日 09:43:40   作者:濁清。。。  
這篇文章主要介紹了微信小程序vant輸入框問題,本文給大家分享完美解決方案,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

在開發(fā)時(shí)候需要添加評論,點(diǎn)擊的時(shí)候從底部彈起,效果如下圖

開發(fā)過程中遇到的問題有如下幾個(gè):

1.van-field 搭配 van-popup
個(gè)別手機(jī)彈出后會導(dǎo)致輸入框位置亂跳,問題原因是van-popup多次彈出數(shù)據(jù)渲染會有一定問題
2.van-field 搭配 van-overlay(遮罩)
遮罩彈出太慢,手機(jī)性能比較差的體驗(yàn)太差
3.IOS自動(dòng)推上去內(nèi)容跑掉

處理方案:

自義定遮罩,利用display進(jìn)行設(shè)置,手機(jī)性能差的也幾乎不會卡頓
參考的是網(wǎng)上一個(gè)小哥代碼:http://www.dbjr.com.cn/javascript/2976631fc.htm

// wxml代碼
// catchtouchmove="true" 對遮罩的穿透處理
<view class="overlayInput" style='display:{{showInput ? "block" : "none"}}' catchtouchmove="true" bindtap="onCancel"></view>
// wxss代碼
// 這邊代碼是之前百度網(wǎng)上一個(gè)哥們的代碼,
.overlayInput {
  display: none;
  position: fixed;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  background-color: black;
  z-index: 2;
  -moz-opacity: 0.7;
  opacity: 0.70;
  filter: alpha(opacity=70);
}

van-field代碼如下,因?yàn)槊看吸c(diǎn)擊評論按鈕需要自動(dòng)吊起鍵盤,所以加一個(gè)wx:if,這樣每次autofoucus都會生效,我這邊是寫成一個(gè)組件,父級調(diào)用的時(shí)候傳值下來showInput

<view class="comInput" style="bottom: {{isBlur ? blurBottom : bottom}}px" wx:if="{{showInput}}">
  <view class="top hairline">
    <view class="cancel" bindtap="onCancel">取消</view>
    <view class="title">發(fā)表觀點(diǎn)</view>
    <view class="release" bindtap="onRelease">發(fā)布</view>
  </view>
  <view class="comtent">{{title}}</view>
  <view style="padding:0 10px 10px 10px;">
    <van-field
      value="{{ inputValue }}"
      placeholder="內(nèi)容經(jīng)過官方合規(guī)性審查通過后對所有人可見"
      border="{{ false }}"
      cursor-spacing="95"
      input-class="border"
      bind:change="onChange"
      autosize="{{autoSize}}"
      bind:keyboardheightchange="keyboardheightchange"
      maxlength="200"
      adjust-position="{{false}}"
      arrow-direction="left"
      fixed="{{true}}"
      type="textarea"
      bind:focus="onFoucs"
      bind:blur="onBlur"
      bind:linechange="onLineChange"
      show-word-limit
      auto-focus
      focus
      placeholder-class="place"
      input-class="com-input-class"
      show-confirm-bar="{{ false }}"
    />
  </view>
</view>

優(yōu)化處理:

由于小程序本身性能問題,每次鍵盤喚醒都可以看到很明顯的卡頓,這邊參考了微博小程序的做法,第一次彈起的時(shí)候記錄一下位置,下次彈起直接跳轉(zhuǎn)到對應(yīng)位置

組件全部代碼如下,有需要可以自行提取使用,需要自己修改部分:

// 樣式
.overlay {
  display: none;
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  background-color: black;
  z-index: 2;
  -moz-opacity: 0.7;
  opacity: 0.70;
  filter: alpha(opacity=70);
}
.comInput {
  /* height: 200px; */
  position: fixed;
  width: 100%;
  background: #fff;
  z-index: 20;
  /* bottom: 0; */
  border-radius: 26rpx 26rpx 0 0;
}
.top {
  padding: 10px 16px;
  text-align: center;
}
.cancel {
  float: left;
  width: 50px;
  text-align: left;
}
.title {
  display: inline-block;
}
.release {
  float: right;
  width: 100rpx;
  height: 50rpx;
  background:rgba(255,194,64,1);
  border-radius: 25rpx;
  font-size: 30rpx;
}
.hairline {
  border-bottom: 1px solid #efefef;
}
.comtent {
  padding: 10px 16px;
}
.com-input-class {
  background: #efefef;
  border-radius: 3px;
  padding: 5px 5px 5px 5px;
}
.place {
  color:red;
}
// wxml代碼
<view class="overlay" style='display:{{showInput ? "block" : "none"}}' catchtouchmove="true" bindtap="onCancel"></view>
<view class="comInput" style="bottom: {{isBlur ? blurBottom : bottom}}px" wx:if="{{showInput}}">
  <view class="top hairline">
    <view class="cancel" bindtap="onCancel">取消</view>
    <view class="title">發(fā)表觀點(diǎn)</view>
    <view class="release" bindtap="onRelease">發(fā)布</view>
  </view>
  <view class="comtent">{{title}}</view>
  <view style="padding:0 10px 10px 10px;">
    <van-field
      value="{{ inputValue }}"
      placeholder="內(nèi)容經(jīng)過官方合規(guī)性審查通過后對所有人可見"
      border="{{ false }}"
      cursor-spacing="95"
      input-class="border"
      bind:change="onChange"
      autosize="{{autoSize}}"
      bind:keyboardheightchange="keyboardheightchange"
      maxlength="200"
      adjust-position="{{false}}"
      arrow-direction="left"
      fixed="{{true}}"
      type="textarea"
      bind:focus="onFoucs"
      bind:blur="onBlur"
      bind:linechange="onLineChange"
      show-word-limit
      auto-focus
      focus
      placeholder-class="place"
      input-class="com-input-class"
      show-confirm-bar="{{ false }}"
    />
  </view>
</view>
// js代碼
Component({
  /**
   * 組件的屬性列表
   */
  properties: {
    inputValue: String,
    title: String,
    showInput: {
      value: false,
      type: Boolean
    }
  },
  /**
   * 組件的初始數(shù)據(jù)
   */
  data: {
    autoSize: {
      maxHeight: 100,
      minHeight: 100
    },
    show: false,
    value: "",
    bottom: 0,
    isBlur: true,
    blurBottom: 0
  },
  /**
   * 組件的方法列表
   */
  methods: {
    keyboardheightchange (e) {
      // this.setData({
      //   bottom: e.detail.height
      // })
    },
    onFoucs (e) {
      this.setData({
        bottom: e.detail.height,
        isBlur: false
      })
    },
    onLineChange (e) {
    },
    onBlur (e) {
      this.setData({
        isBlur: true
      })
    },
    onShowInput () {
      this.setData({
        show: true
      })
    },
    onCancel () {
      console.log("點(diǎn)擊了取消")
      this.setData({
        show: false
      })
      this.triggerEvent("close")
    },
    onRelease () {
      if (!this.data.inputValue.trim()) 
      return  wx.showToast({
          title: "請?zhí)顚懺u論內(nèi)容",
          icon: 'none',
          duration: 2000
        })
      this.triggerEvent("onOneComment", this.data.inputValue)
      this.onClose()
    },
    onChange (e) {
      this.data.inputValue = e.detail
      this.triggerEvent("onInput", e.detail)
    },
    onClose () {
      this.setData({
        show: false
      })
      this.triggerEvent("close")
    }
  }
})

到此這篇關(guān)于微信小程序vant 輸入框問題的文章就介紹到這了,更多相關(guān)微信小程序vant 輸入框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論