MorganRowse's avatar

Blade usage in Vue component files - Best practice/Workflow

Hi all,

Currently wondering what workflow to use when using

  • The Laravel Router
  • Vue components in separate .vue files

With Laravel and blade

In the past I've been doing such:

index.blade.php

<table>
    @foreach($items as $item)
        <tr>
            <td>
                <a href="{{route('items.show',$item->id)}}">View Item</a>
            </td>
        </tr>
    @endforeach
</table>

With Vue

Now learning Vue I've been doing something like this:

index.blade.php

<item-table></item-table>

ItemTable.vue

<table>
    <tr v-for="item in items">
        <td>
            <a :href=" 'items/'+ item.id">View item</a>
        </td>
    </tr>
</table>

My question is this:

  • Is it good practice to v-bind: the route as a prop to the component?
  • If for instance that the view page is no longer on items/view/id (as its hard-coded on the component) or the <item-table> component is used in a directory not relevant to items/view there will be routing issues, is this acceptable practice? (From what Laracast Vue series I have seen, all of the axios routes are hardcoded)
  • Do you pass along many props like this ie: auth:user() or is there a better way to transfer blade directives that I'm missing?

Just feeling like a lot of the power of Blade is lost in exchange for the reactivity of vue.

Thanks in advance! :)

0 likes
3 replies
robrogers3's avatar
Level 37

I think you have a good point. especially when the page is mainly js. Your stuck passing all the props in via blade.

you can check out vuex, but that maybe overkill, where a simple object pumped out and accessed via your Vue instance/component would be fine.

but if you only have a handful of props and your components aren't too deeply nested, passing them in is not bad.

so in this case, pass the href as a prop, and the user too.

you could create a global function for getting the user though. In fact it's already there.

window.Laravel.user

2 likes
MorganRowse's avatar

Thank you for the response @robrogers3

Will have to see how route props align with workflow as I experience more of Vue but quite confident I will run into issues on larger projects with translations => trans() and nested components.

Vuex may just be the answer.

robrogers3's avatar

so solved for now?

ps. if the props/attributes/whatever are read only than vuex is definitely over kill.

Please or to participate in this conversation.