What I want to achieve
I have a project using Laravel + InertiaJS/VueJS 3. In it, there is an edit form that should display the content of $page.props.profile_name if the value is not empty or the string profile_name if the value is non-existent.
The bug message from the browser's console
Uncaught (in promise) ReferenceError: $page is not defined
When I see this message, the content of my component is not visible in the interface.
My VueJS 3 Code
<template>
<form @submit.prevent="submit">
<input id="profile_name" v-model="form.profile_name" />
<input id="description" v-model="form.description" />
<button type="submit">Submit</button>
</form>
</template>
<script setup>
import { useForm } from '@inertiajs/vue3';
import { router } from '@inertiajs/vue3';
const form = useForm({
profile_name: $page.props.profile_name || 'profile_name',
description: $page.props.description || 'description',
});
function submit() {
router.post('/members', form);
}
</script>
How I can solve the issue for now
The code works fine, but with hard-coded content, if I replace the form constant this way. I would prefer to get my content from $page.props.profile_name as soon as $page.props.profile_name is not empty.
const form = useForm({
profile_name: 'profile_name',
description: 'description',
});
$pageis a global variable used with Vue 2 syntax. most libraries that have migrated from Vue 2 to Vue 3 have replaced globals with composables. Check out the inertiajs documentation and the "Vue 3" tab which shows how you should utilize theusePagecomposable instead of$page