最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序表單驗證WxValidate的使用

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

效果圖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: '請輸入手機號',
        tel: '請輸入正確格式手機號',
      }, post: {
        required: '請輸入職位',
      }, weChat: {
        required: '請輸入微信號',
      }, specialPlane: {
        required: '請輸入座機號',
      }, email: {
        required: '請輸入電子郵箱',
        email: '請輸入正確格式電子郵箱',
      }
    };
    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
     })
  },
})

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

视频| 浮梁县| 社旗县| 保德县| 中阳县| 高碑店市| 阿城市| 塘沽区| 始兴县| 大足县| 瓮安县| 阿坝| 乌什县| 呼玛县| 井冈山市| 青田县| 泊头市| 元朗区| 宜黄县| 淄博市| 宜都市| 抚顺县| 蓬溪县| 双桥区| 昭通市| 宁德市| 临武县| 泰州市| 广饶县| 荆门市| 荣成市| 甘洛县| 大洼县| 武安市| 郎溪县| 忻城县| 凭祥市| 福清市| 孟州市| 伊宁县| 吉木乃县|