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

微信小程序表單驗(yàn)證WxValidate的使用

 更新時(shí)間:2019年11月27日 11:41:09   作者:Independent  
這篇文章主要介紹了微信小程序表單驗(yàn)證WxValidate的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

效果圖GIF

git地址:WxValidate

使用

import WxValidate from '../../utils/WxValidate';
Page({
  data: {
    basicInfo: {
      tel: '',
      post: '',
      weChat: '',
      specialPlane: '',
      email: '',
      intro: ''
    }
  },
  onLoad() {
    this.initValidate();
  },
  initValidate() {
    const rules = {
      tel: {
        required: true,
        tel: true,
      }, post: {
        required: true,
      }, weChat: {
        required: true,
      }, specialPlane: {
        required: true,
      }, email: {
        required: true,
        email: true
      }
    };
    const messages = {
      tel: {
        required: '請(qǐng)輸入手機(jī)號(hào)',
        tel: '請(qǐng)輸入正確格式手機(jī)號(hào)',
      }, post: {
        required: '請(qǐng)輸入職位',
      }, weChat: {
        required: '請(qǐng)輸入微信號(hào)',
      }, specialPlane: {
        required: '請(qǐng)輸入座機(jī)號(hào)',
      }, email: {
        required: '請(qǐng)輸入電子郵箱',
        email: '請(qǐng)輸入正確格式電子郵箱',
      }
    };
    this.WxValidate = new WxValidate(rules, messages)
  },
  formChange(val) {
    let obj = {}
    obj[`basicInfo.${val.currentTarget.dataset.val}`]= val.detail.value
    this.setData(obj)
  },
  submitForm(e) {
    const params = e.detail.value
    if (!this.WxValidate.checkForm(params)) {
      const error = this.WxValidate.errorList[0]
      this.showModal(error)
      return false
    }
  },
  showModal(error) {
    wx.showToast({
      title: error.msg,
      icon: 'none',
      duration: 2000
     })
  },
})

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論