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

@maybecode/vue-form-validator

v1.0.3

Published

[![npm](https://img.shields.io/npm/v/@maybecode/vue-form-validator.svg)](https://www.npmjs.com/package/@maybecode/vue-form-validator) [![npm](https://img.shields.io/npm/dt/@maybecode/vue-form-validator.svg)](https://www.npmjs.com/package/@maybecode/vue-fo

Readme

😘vue-form-validator

npm npm npm

Demo

demo

安装

npm install @maybecode/vue-form-validator

或者

yarn add @maybecode/vue-form-validator
// main.js

import VueFormValidator from "@maybecode/vue-form-validator";

Vue.use(VueFormValidator);

mv-form props


mv-item props


mv-item scope-slots


<template #default="{errors,fieldValidate}">
<!-- 这里插入内容 -->
</template>
      <template #default="{errors,fieldValidate}">
          <div class="item-row">
            <input type="text" @blur="fieldValidate" v-model="form.code" />
          </div>
          <p v-if="errors && errors.length>0">{{errors}}</p>
        </template>

👉 模板


 <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" />
    <h2>😘vue-form-validator</h2>
    <p>🌟可以高度定制化UI的表单验证组件,不提供任何UI封装,只封装验证逻辑</p>
    <mv-form :model="form" :ref="el" :rules="rules" custom-class="custom-form">
      <h2>默认表单提交触发验证👇</h2>
      <mv-item prop="phone" custom-class="custom-item">
        <template #default="{errors}">
          <div class="item-row">
            <label>手机号:</label>
            <input v-model="form.phone" type="text" />
          </div>
          <p v-if="errors && errors.length>0">{{errors}}</p>
        </template>
      </mv-item>
      <h2>输入触发事件👇</h2>
      <mv-item prop="password" custom-class="custom-item">
        <template #default="{errors,fieldValidate}">
          <div class="item-row">
            <label>密码:</label>
            <!-- 触发函数绑定到自定义的事件上 -->
            <input type="password" @input="fieldValidate" v-model="form.password" />
          </div>
          <p v-if="errors && errors.length>0">{{errors}}</p>
        </template>
      </mv-item>
      <h2>失去焦点触发事件👇</h2>
      <mv-item prop="code" custom-class="custom-item">
        <template #default="{errors,fieldValidate}">
          <div class="item-row">
            <label>验证码:</label>
            <input type="text" @blur="fieldValidate" v-model="form.code" />
          </div>
          <p v-if="errors && errors.length>0">{{errors}}</p>
        </template>
      </mv-item>
      <h2>select值改变触发事件👇</h2>
      <mv-item prop="select" :rules="[{ required: true, message:'必须选择一个选项',type:'string'}]">
        <template #default="{errors,fieldValidate}">
          <div class="item-row">
            <label>选项验证:</label>
            {{form.select}}
            <select
              v-model="form.select"
              @change="customSelectChange(fieldValidate)"
            >
              <option :value="null">空值</option>
              <option value="1">第一个</option>
              <option value="2">第二个</option>
            </select>
          </div>
          <p v-if="errors && errors.length>0">{{errors}}</p>
        </template>
      </mv-item>
      <!-- 这里要设置button的type为submit-->
      <button style="margin:15px 0px;" type="submit" @click.prevent="validate">提交</button>
    </mv-form>
  </div>

👉 配置


export default {
  name: "Home",
  components: {
    MvForm,
    MvItem,
  },
  data() {
    return {
      el: "formbbb",
      form: {
        username: "",
        password: "",
        code: "",
        select: "",
      },
      // 具体验证规则参考 https://github.com/yiminghe/async-validator
      rules: {
        phone: [
          { required: true, message: "请填写手机号" },
          {
            message: "请输入正确手机号",
            // 自定义验证逻辑
            validator(rule, value, callback) {
              const reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
              return reg.test(value);
            },
          },
        ],
        password: [
          { required: true, message: "请填写密码", type: "string" },
          { message: "密码最多10位", max: 10 },
        ],
        code: [
          { required: true, message: "请填写验证码", type: "string" },
          { message: "验证码4位", len: 4 },
        ]
      },
    };
  },
  methods: {
    customSelectChange(validate) {
      // 自定义验证的时机
      validate();
    },
    // 表单提交验证
    validate() {
      console.log(this.$refs);
      this.$refs[this.el].validate((err) => {
        console.log(err);
      });
    },
  },
};

Typescript

import { MvForm } from "@maybecode/vue-form-validator";

 validate() {
     (this.$refs["form"] as MvForm).validate((err) => {
        console.log(err);
      });
    },