All files / src index.js

0% Statements 0/19
0% Branches 0/16
0% Functions 0/2
0% Lines 0/14
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 32 33 34 35 36 37                                                                         
import validator from './validator/index.js'
import Directive from './directive.js'
import lang from './locale'
 
/**
 * VUE plugin registed function
 * @param {Object} Vue object 
 * @param {Object} plugin config object 
 */
 
function install (Vue, options = {}) {
  options.lang = options.lang || 'zh_cn'
  Object.assign(validator, options.validators)
  Object.assign(lang[options.lang], options.messages)
  try {
    const directive = new Directive(Vue, {
      mode: options.mode,
      errorIcon: options.errorIcon,
      errorClass: options.errorClass || null,
      errorForm: options.errorForm,
      validators: validator,
      messages: lang[options.lang]
    })
    directive.install(Vue)
  } catch (e) {
    console.error(`${e}\nfrom v-verify`)
  }
}
 
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}
 
export default {
  install
}