Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TheTalker85's avatar

Setting Prop from Laravel blade to Vue component is undefined?

Hi,

I am setting a prop (currentPage) from my blade template and trying to access it in my vue component but it is always undefined and i don't understand why, or what i am doing wrong? Everything else from the vue component is loading ok i.e. all the html

Blade

<div id="app">
    <!-- Vue Header -->
        <header-menu :currentPage="'home'"></header-menu>
</div>

HeaderMenu.vue

<script setup>
import { ref } from 'vue';

const props = defineProps({
    currentPage: {
        type: String
    }
});

console.log(props.currentPage);


const mobileMenuOpen = ref(false);
const mobileButtonClickHandler = () => {
    mobileMenuOpen.value = !mobileMenuOpen.value;
}

</script>

<template>
<!-- header html -->
</template>

app.js

import './bootstrap';
import { createApp, defineAsyncComponent } from 'vue/dist/vue.esm-bundler';
import HeaderMenu from './components/HeaderMenu.vue';

const app = createApp({
    mounted() {
        console.log('The app is working')
    }
});

app.component('header-menu', HeaderMenu);


app.mount('#app');

0 likes
6 replies
LaryAI's avatar
Level 58

It looks like you're trying to pass a string literal as a prop from your Blade template to your Vue component. In Vue 3, when you use the v-bind syntax (or the shorthand :), you don't need to use quotes for string literals. Here's how you can fix the issue:

In your Blade file, you should pass the string without single quotes:

<div id="app">
    <!-- Vue Header -->
    <header-menu :current-page="'home'"></header-menu>
</div>

In your Vue component, you should be able to access the currentPage prop as you have defined it. However, make sure that you are using the correct case for the prop name in your template. Vue.js automatically converts camelCase prop names into kebab-case in templates. So, if you're using currentPage in your JavaScript, you should use current-page in your template.

Here's the corrected HeaderMenu.vue:

<script setup>
import { ref } from 'vue';

const props = defineProps({
    currentPage: {
        type: String,
        default: ''
    }
});

console.log(props.currentPage);

const mobileMenuOpen = ref(false);
const mobileButtonClickHandler = () => {
    mobileMenuOpen.value = !mobileMenuOpen.value;
}
</script>

<template>
<!-- header html -->
<!-- Use the prop in your template like this: -->
<div>{{ currentPage }}</div>
</template>

Make sure that your app.js is correctly importing Vue and your component, which seems to be the case based on the code you've provided.

If you're still encountering issues, ensure that:

  1. Your Vue component file is correctly named and located in the path you're importing from.
  2. You don't have any console errors in your browser's developer tools that could indicate other issues.
  3. Your Vue version in package.json matches the syntax you're using (the code provided assumes Vue 3).

If you've checked all of the above and it's still not working, you might want to clear your mix cache and recompile your assets to make sure you're not serving an old version of your JavaScript file:

npm run dev

or if you're using Laravel Mix:

npx mix

Remember to refresh your browser, sometimes with a hard refresh (Ctrl + F5 or Cmd + Shift + R) to clear the cache.

coni's avatar
coni
Best Answer
Level 28

Please try this syntax:

<header-menu current-page="home"></header-menu>
TheTalker85's avatar

@Coni

Many thanks! This has worked.

Could you explain why? With previous projects i have aways matched the case to the prop e.g. currentPage in both places.

1 like
coni's avatar

@TheTalker85 It depends where You use prop. Full explanation is under link previously posted.

1 like

Please or to participate in this conversation.