| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import Vue from 'vue'
- import VeeValidate, {Validator} from 'vee-validate'
- import zh from 'vee-validate/dist/locale/zh_CN'
- import VueI18n from 'vue-i18n'
- Vue.use(VueI18n)
- const i18n = new VueI18n({
- locale: 'zh_CN'
- })
- Vue.use(VeeValidate, {
- i18n,
- i18nRootKey: 'validation',
- dictionary: {
- zh
- }
- })
- // 配置中文
- // Validator.addLocale(zh)
- const config = {
- locale: 'zh_CN'
- }
- Vue.use(VeeValidate, config)
- // 自定义validate
- const dictionary = {
- zh_CN: {
- messages: {
- vipName: () => '用户名不能为空',
- required: (field) => '请输入' + field
- },
- attributes: {
- vipName: '会员名'
- }
- }
- }
- console.log('1', dictionary)
- console.log(Validator)
- Validator.localize('zh_CN', dictionary)
- // 自定义会员名验证
- Validator.extend('vipName', {
- getMessage: field => field + '会员名不能为空',
- validate: value => {
- return value.length === ''
- }
- })
- // 自定义手机验证
- Validator.extend('phone', {
- getMessage: field => field + '必须是11位手机号码',
- validate: value => {
- return value.length === 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
- }
- })
|