So I’m thinking about the structure for my restaurant web page which will use laravel as the back-end (routing and displaying blade views to the browser, easy auth system and sessions) and vue.js for the front-end (I have a single vue instance where I register components, this components are each one a view, a whole page, most of these pages have 2 or 3 components nested, like an image slider, to-top anchor, I use axios to fetch my API endpoints without refreshing the page plus many CRUD operations from an admin panel).
This is how my index.blade.php view looks ( www.domain.com/ ), I have many views like posts.index.blade.php…
@extends('layouts.master')
@section('content')
<page-index></page-index)
@endsection
As you can see, I want to treat each page as a vue.component with many components nested inside of each page component).
I have a few questions about possible complications using this structure.
When displaying views I always return a json object with all the data I want to render on blade, since each page is basically a vue.js component loaded via javascript how will I able to loop through the dishes, events and posts I fetched from the backend. This is, I want to use the v-for directive but how can my component know of the data passed to blade? I donn’t want to use axios on mounted to populate my views… that would increase drastically the number of requests send to the backend.
Since the whole page content is rendered via javascript won’t this affect negatively SEO?? afaik search engones crawlers won’t fetch the content displayed by javascript.
Is this a good practice, is this the best way to handle laravel + vue.js non-SPA? Is this a good abstraction of front-end and back-end?
How I will handle auth is by doing axios requests to laravel login endpoints.
2
Answers
Your app structure wants vue.js files and id of the element where it can render components:
Remember! You have to include vue.js files where you want to use vue in laravel application
For passing data to your vue component, you can use props.
IndexController.php
index.blade.php
PageIndexComponent.vue
Here you can do your
v-for
loop withparsedEvents
.For SEO, you can edit your
resources/views/layouts/master.blade.php
:And in each view you can either hardcode your title, description etc or send it from your Controllers: