Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

메모장

Vue vee-validate 본문

JavaScript

Vue vee-validate

doopang 2023. 3. 14. 09:43
npm i vee-validate

 

vee-validate.js

import {confirmed, email, integer, length, max, min, min_value, numeric, required, regex, double} from 'vee-validate/dist/rules'
import {extend, localize} from 'vee-validate'
import ko from 'vee-validate/dist/locale/ko.json'

localize('ko', ko)

extend('required', {
  ...required,
  // message: 'This field is required1'
})

 

Company.vue

<template>
  <ValidationObserver ref="observer" v-slot="{ passes }" tag="div">
    <form @submit.prevent="passes(onSubmit)">
      <ValidationProvider v-slot="{ errors }" tag="div" class="form-label-group"
                          name="company-name"
                          rules="required"
                          :custom-messages="{ 'required': '회사명은 필수 정보입니다.'}">
        <input type="text" class="form-control" placeholder="회사명" v-model="companyName">
        <span class="text text-danger pt-2 pl-2 d-block" v-if="errors[0]">{{ errors[0] }}</span>
      </ValidationProvider>
    </form>
  </ValidationObserver>    
</template>

<script>
import {ValidationObserver, ValidationProvider} from 'vee-validate';

export default {
  components: {
    ValidationObserver,
    ValidationProvider
  }
}
</script>

'JavaScript' 카테고리의 다른 글

Vue props, emit  (0) 2023.11.21
TOAST UI Grid Pagination Using Callbacks  (0) 2023.09.16
FormData 로그 보기  (0) 2023.02.20
Storage  (0) 2023.01.27
Vue Excel JSON 형식으로 Parsing  (0) 2023.01.17