中英文切换时,遇到表单验证的提示没有同时更新
message内容,不能放在 rules中,要单独写
data () {
const validateSmoke = (rule, value, callback) => {
if (!value) {
return callback(new Error(this.$t(`home.${rule.field}IsRequired`)))
} else {
return callback()
}
}
return{
rules: {
smoke: [{ required: true, validator: validateSmoke, trigger: ['blur', 'change']}],
}
}
}
监听i18n,切换语言时查找已经提示错误的表动项,手动触发验证
watch: {
'$i18n.locale': {
handler (locale) {
this.$nextTick(() => {
this.$refs['form'].fields.forEach(item => {
if (item.validateState === 'error') {
this.$refs['form'].validateField(item.labelFor)
}
})
})
},
immediate: true,
deep: true
}
},