1.0.3 • Published 5 years ago

z-vue-validator v1.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago
npm i z-vue-validator

在index.js使用插件

import Validator from 'vue-validator'

Vue.use(Validator)

模板语法

<input type="text" 
  v-model="phone" 
  v-validate.input="'phone'"
  />

<span>{{validateResult.phone}}</span>

<button @click="submit">提交</button>

规则定义与方法调用

import {validatorMixin} from 'vue-validator'
export default {
  mixins: [validatorMixin],
  data () {
    return {
      phone: ''
    }
  },
  validator () {
    return {
      phone: [
        {
          need: () => !!this.phone,
          warn: "请输入法人手机号码"
        },
        {
          need: () => {
            let reg = /^\d{11}$/
            return reg.test(this.phone)
          },
          warn: "请输入正确的法人手机号码"
        }
      ]
    }
  },
  methods: {
    submit () {
      if (this.$validator.validateAll()) {
        alert('ok submit')
      }
    }
  }
}
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago