0👍
✅
Apparently I didn’t understand it completely. This fixed it for me:
// useValidationRules.ts
import { useI18n } from 'vue-i18n-composable'
export const useValidationRules = () => {
const { t } = useI18n()
const requiredRule = (val: string) =>
!!val || t('validationRules.requiredField')
return { requiredRule }
}
Usage:
import { useValidationRules } from 'src/composables/useValidationRules'
export default defineComponent({
setup() {
const { requiredRule } = useValidationRules()
const answerInputValidationRules = computed(() => {
return [requiredRule]
})
return { answerInputValidationRules }
},
})
Source:stackexchange.com