日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

微信小程序批量獲取input的輸入值,監聽輸入框,數據同步

作者:沉、睡 更新時間: 2022-02-01 編程語言

微信小程序批量獲取input的輸入值,監聽輸入框,數據同步

在使用小程序時,跟vue的數據綁定不一樣,沒有v-model這個屬性了,官網也只是給了一些事件監聽。

但是我們如果有多個表單時,需要寫多個事件來同步數據。這樣做很麻煩。下面的方法可以解決,只需要一個方法即可。

wxml:

<view class="cu-form-group">
      <view class='title'>姓名</view>
      <input placeholder="請輸入姓名" class='radius' bindinput="bindKeyInput" data-name="sorterInfo.shopName" value="{{sorterInfo.shopName}}"></input>
</view>
<view class="cu-form-group">
      <view class='title'>賬號</view>
      <input placeholder="請輸入賬號" class='radius' bindinput="bindKeyInput" data-name="sorterInfo.username" value="{{sorterInfo.username}}"></input>
</view>
<view class="cu-form-group">
      <view class='title'>密碼</view>
      <input placeholder="請輸入密碼" class='radius' type="password" bindinput="bindKeyInput" data-name="sorterInfo.password" value="{{sorterInfo.password}}"></input>
</view>
<view class="cu-form-group">
      <view class='title'>確認密碼</view>
      <input placeholder="請輸入確認密碼" class='radius' type="password" bindinput="bindKeyInput" data-name="sorterInfo.password2" value="{{sorterInfo.password2}}"></input>
</view>

js:

/**
   * 輸入框更改事件
   * @param {*} e 
   */
  bindKeyInput: function (e) {
    let item = e.currentTarget.dataset.name;
    this.setData({
      [item]: e.detail.value
    });
  },

原文鏈接:https://blog.csdn.net/zz975896590/article/details/119991157

欄目分類
最近更新