Download the PHP package riverskies/laravel-vue-component without Composer
On this page you can find all versions of the php package riverskies/laravel-vue-component. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download riverskies/laravel-vue-component
More information about riverskies/laravel-vue-component
Files in riverskies/laravel-vue-component
Package laravel-vue-component
Short Description Helper package to aid usage of Vue Components within Laravel projects
License MIT
Informations about the package laravel-vue-component
Laravel Vue Component
A helper package to aid working with Vue Components in a (non-SPA) Laravel environment. This package makes injecting page-specific Vue Components a breeze.
Sometimes we come across situations where the project is not using Vue extensively, but some pages could highly benefit from it being present. This package aims at those scenarios and makes it possible to (optionally) wrap pages with dedicated Vue components directly from your PHP backend.
When would you use this package?
When building a multi-page application there is often a need to inject some Vue magic into specific pages. However, more often then not, as the project grows, the individual script tags get out of control and become very hard to manage.
How does this package work?
The package implements a new Blade directive that you can safely use to wrap your yielded content in your Blade templates. By using this new directive you are able to inject a custom, page-specific Vue component into any of your pages while keeping your scripts modular therefore manageable at the same time.
Installation
NOTE - For those with Laravel 5.2 or before: please use v1.0.2 instead!!!
Install the package through composer:
If you're running Laravel 5.4 or earlier, add the service provider to your config/app.php file:
Usage
Wrap your yield block in your layout file with the new directive:
If you have $component
variable set on your view...
...the content
will be wrapped within a dynamic Vue component:
To inject the homepage component dynamically, you will need to have the set component (homepage
) available on your root Vue instance. For example, your app.js file might look like this:
Examples
1. Simple page injection
An example where you connect a blade template to a Vue page instance. Consider following scenario...
In your controller method:
In your pages.contact.blade
file (note the wrapping <div>
and the escaped @{{ ... }}
syntax):
In your pages/contact.js
file:
And your main app.js
file to be like this:
With above, you are successfully injected VueJS control into your contact page.
2. Sending through data
Based on Example 1, you can send through data from the backend directly as well. Consider following scenario...
In your controller method:
In your pages/contact.js
file:
This method can be used to send through data from the backend directly.