#Watch props

1 messages · Page 1 of 1 (latest)

unkempt raven
#

Hey 👋

I'm trying to retrieve errors from a POST request.

Backend

 return redirect()->back()->withErrors(['foo' => 'bar']);

Frontend

<script setup>
import { computed, watch } from 'vue'
import { usePage, router } from '@inertiajs/vue3'

const { props } = usePage()
const errors = computed(() => props.errors)

watch(errors, (newErrors) => {
    console.log(newErrors)
})

function submit() {
    router.post('/foo')
}
</script>

What am I missing?

Thank you 😄

hazy tartan
#

Why don’t you use the use form helper?

#

You will have the erros in the form object

unkempt raven
cunning minnow
#

Inertia also provides a onError callback you can use

unkempt raven