[Vuejs]-Vue 3 reusable error handling and handleSubmit in reusable 'useForm' function using the composition api

0👍

Regarding your first question – try..catch statements have a third statement called finally which always executes after the try statement block has completed.

To answer your second question – promises are a great way of handling async logic, including your case when the API you’re sending the request to returns an error response, and you can then decide how you’re going to handle the UX in such scenario.

I’m not quite clear on what you mean by handle the errors in Login.vue in a reusable way, but perhaps you could simple pass in an empty array prop to your useForm called formErrors and have your useForm.js emit an update:modelValue event to get two way binding.

Leave a comment