1.0.6 • Published 5 months ago

@team-decorate/vue3-validate-plugin v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Installing

Using yarn:

$ yarn add @team-decorate/vue3-validate-plugin

Once the package is installed, you can import the library using import approach:

import { ValidatePlugin, useValidate, ValidateWrap } from '@team-decorate/vue3-validate-plugin'

Example

How to install to app:

Note: Insert exception You can insert your own error by passing registerError as an option. Please register with IRegisterError type

import {createApp} from 'vue'
import App from '@/App.vue'
import axios from 'axios'
import {ValidatePlugin} from '@team-decorate/vue3-validate-plugin'

const app = createApp(App)
app.use(ValidatePlugin, {
	axios: axios,
	registerError: [
		{codeCondition: (n) => n == 430, error: PermissionError}
	], //optional
})

How to use ValidateWrap:

<script setup lang="ts">
import {ValidateWrap, ValidateError, useValidate} from '@team-decorate/vue3-validate-plugin'
import axios from 'axios'

const {setValidError} = useValidate()

const submit = async () => {
    try {
        await axios.post('/api/some', data)
    } catch (e) {
        if (e instanceof ValidateError) {
            setValidError(e)
        }
    }
}
</script>

<template>
    <validate-wrap>
        <div class="mb-3">
            <label>name</label>
            <input v-model="user.name" class="form-control" data="name">
        </div>
        <div class="mt-3">
            <label>email</label>
            <input v-model="user.email" class="form-control" data="email">
        </div>
    </validate-wrap>
    <button @click="submit">submit</button>
</template>

example

Props:

Namedefaultdescription
attributeFielddatakey to detect validate error
1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago