1.5.3 • Published 3 years ago

@arshown/vue3-validate v1.5.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

vue3-validate

一個基於 vuelidate 所延伸並適用於 vue3 的表單驗證套件

npm.io

Install

> npm install @vuelidate/core @arshown/vue3-validate
# or
> yarn add @vuelidate/core @arshown/vue3-validate

Usage

複寫原 @vuelidate/core 的 useVuelidate 使用方式,添加驗證訊息

<script>
import { reactive } from "vue";
import { useValidate } from "@arshown/vue3-validate";
import { required, minLength } from "@vuelidate/validators";

export default {
  setup() {
    const form = reactive({
      name: "",
    });
    const rules = {
      name: {
        required,
        minLength: minLength(4),
      },
    };
    const messages = {
      name: {
        required: "名稱為必填",
        minLength: () => ({ min }) => `長度至少為 ${min}`,
      },
    };

    const v$ = useValidate(rules, form, messages);

    return { form, v$ };
  }
}
</script>

minLength 參數參考: https://github.com/vuelidate/vuelidate/blob/next/packages/validators/src/withMessages/minLength.js

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago