npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@whaoa.w/element-ui-form-verify

v0.1.4

Published

一款更友好的 ElementUI Form 校验插件

Downloads

1

Readme

element-ui-form-verify

一个更友好的 Element-UI Form 校验插件「基于 Element-UIElFormItem 组件进行非侵入式扩展包装」。

安装

yarn add @whaoa.w/element-ui-form-verify
import Vue from 'vue';

import ElementUI from 'element-ui';
import ElementUIFormVerify from '@whaoa/element-ui-form-verify';

Vue.use(ElementUI);
// 必须在注册 ElForm 组件后进行注册
Vue.use(ElementUIFormVerify);

基本使用

仅在 ElFormItem 组件的标准用法上添加 verify 属性相应校验规则名称 即可开启校验。


<template>
  <el-form ref="form" :model="form" label-width="100px">
    <!-- 必填 -->
    <el-form-item prop="text" label="文本" verify>
      <el-input v-model="form.text" placeholder="请输入文本"/>
    </el-form-item>
    <!-- 数字 -->
    <el-form-item prop="number" label="数字" verify number>
      <el-input v-model="form.number" placeholder="请输入数字"/>
    </el-form-item>
    <!-- 最小内容长度 -->
    <el-form-item prop="minLength" label="最小长度(2)" verify :min-length="2">
      <el-input v-model="form.minLength" placeholder="最小长度(2位)的内容"/>
    </el-form-item>
    <!-- 手机号 -->
    <el-form-item prop="phone" label="手机号" verify phone>
      <el-input v-model="form.phone" placeholder="请输入手机号"/>
    </el-form-item>
    <!-- 邮箱,非必填 -->
    <el-form-item prop="email" label="邮箱" verify email can-be-empty>
      <el-input v-model="form.email" placeholder="请输入邮箱"/>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      form: {
        text: '',
        number: '',
        minLength: '',
        phone: '',
        email: '',
      },
    };
  },
};
</script>

自定义校验规则

插件支持两种自定义校验规则的方式:

  1. 注册全局校验规则「如内置的 number 的规则」
  2. 针对单个字段自定义校验规则

注册全局校验规则

import ElementUIFormVerify from '@whaoa.w/element-ui-form-verify';

Vue.use(ElementUIFormVerify);

// 必须在 use 后调用
ElementUIFormVerify.addRule(
  // 规则名称
  'maxLength',
  // 规则所接受的 Prop value 类型
  Number,
  // 规则生成函数,返回 AsyncValidator 所支持的规则数组,即 ElForm 原生支持的 rules prop
  function({ value }) {
    return [
      // 继承已有校验规则配置,getRule 返回包装后的校验规则生成函数
      // 可以传入参数,参数与在 vue 中在 el-form-item 组件上通过 prop 传入的数据格式
      ...ElementUIFormVerify.getRule('number')(),
      // 自定义校验规则
      { pattern: /^([-+])?\d+(\.\d+)?$/, message: '请输入数字' },
    ];
  },
);

自定义单个字段校验规则


<template>
  <el-form ref="form" :model="form" label-width="100px">
    <el-form-item prop="word" label="英文字符" :verify="wordVerify">
      <el-input v-model="form.word" placeholder="请输入英文字符"/>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      form: {
        word: '',
      },
    };
  },

  methods: {
    wordVerify({ getRule }) {
      return [
        // 可通过 getRule 函数获取已有校验规则
        // 第一个参数为规则名称,第二个参数为规则生成函数所接受的参数
        // 返回规则配置数据
        ...getRule('maxLength', 3),
        { pattern: /^[a-zA-Z]+$/, message: '请输入英文字符' },
      ]
    },
  },
};
</script>

API

ElFormItem Prop

| 参数名称 | 参数类型 | 描述 | |---------------|-----------------------------------------|--------------------------------------------------------------------------------------| | verify | boolean / function | 校验开关,值为 布尔值类型 时 控制是否开启字段校验,值为函数类型时用于自定义校验规则,此规则最后执行 | | can-be-empty | boolean | 是否必填 | | | empty-message | string | 空值提示文本 | | error-message | string | 校验未通过时提示文本,会覆盖规则内自定义的 message | | [rule-name] | any / { value?: any, message?: string } | 自定义校验规则,值为非对象类型时,会被转换为对象格式的 value 属性传入自定义校验规则生成函数,message 为自定义错误提示文本,会覆盖规则内的 message |