1.0.8 • Published 1 year ago

verify-form v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

100行代码实现轻量级的表单验证组件

live demo

API

  • initial-regular :Boolean // 首次加载就对初始化值进行rules的规则校验
  • inline :Boolean // 将regular-form-fields改为行内元素

refEl

  • $reset :Function // 清空form下所有的错误消息
  • $clear :Function // 清空form下所有表单内容
  • getStatus : Function // 获取form的状态,true表明当前所有rules配置都通过了,否则存在校验错误项
  • getErrorMsg : Function // 获取form的错误消息
  • autoFocus :Function // 自动聚焦第一个错误项

FormData数据结构

const formData = reactive({
  age: '',
  name: '',
  country: '',
  address: '',
  rules: {
    age: [
      /* required */ val => !!val || 'Required',
      /* number */ val => !isNaN(Number(val)) || 'Expected number',
      /* length */ val =>
        val <= 18 ? 'You are too young' : val >= 100 ? 'You are too old' : '',
    ],
    name: [
      /* required */ val => !!val || 'Required',
      /* length */ val => val.length > 2 || 'Length needs to be more than 2',
    ],
  },
})

安装

npm install -D verify-form

注册

import { createApp } from 'vue'
import { VerifyForm, VerifyFormField } from 'verify-form'

const app = createApp(App)
app.component('VerifyForm', VerifyForm)
app.component('VerifyFormField', VerifyFormField)
app.mount('#app')

使用

script template

依赖

vue

1.0.8

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.14-beta.3

2 years ago

0.0.14-beta.2

2 years ago

0.0.14-beta.1

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago