So I want to check if the props
received from HandleInertiaRequest
is null or not in my v-if
from my vue component, but it always throws error like this
Navbar.vue:66 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'name')
at Proxy._sfc_render (Navbar.vue:66:46)
at renderComponentRoot (runtime-core.esm-bundler.js:816:16)
at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5701:46)
at ReactiveEffect.run (reactivity.esm-bundler.js:178:19)
at instance.update (runtime-core.esm-bundler.js:5814:51)
at setupRenderEffect (runtime-core.esm-bundler.js:5822:5)
at mountComponent (runtime-core.esm-bundler.js:5612:5)
at processComponent (runtime-core.esm-bundler.js:5565:9)
at patch (runtime-core.esm-bundler.js:5040:11)
at mountChildren (runtime-core.esm-bundler.js:5284:7)
I do it by using v-if
like this
<div v-if="$page.props.auth.user.name">
<p>{{ $page.props.auth.user.name }}</p>
</div>
<div v-else>
<Link :href="route('login')">
<p class="btn btn-ghost">Sign in</p>
</Link>
</div>
but when the props is not null it succeeded doing the if statement, but when it is null it throws that error
I've already tried to use isset
but it still throws an error
<div v-if="isset($page.props.auth.user.name)">
<p>{{ $page.props.auth.user.name }}</p>
</div>
<div v-else>
<Link :href="route('login')">
<p class="btn btn-ghost">Sign in</p>
</Link>
</div>