Download the PHP package jhoff/blade-vue-directive without Composer
On this page you can find all versions of the php package jhoff/blade-vue-directive. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jhoff/blade-vue-directive
More information about jhoff/blade-vue-directive
Files in jhoff/blade-vue-directive
Package blade-vue-directive
Short Description Vue directive for Laravel Blade
License MIT
Homepage https://github.com/jhoff/blade-vue-directive
Informations about the package blade-vue-directive
Laravel Blade Vue Directive
Laravel Blade Vue Directive provides blade directives for vue.js single file and inline template components.
- Upgrade from 1.1.x to 2.0.0
- Installation
- Usage
- Basic Example
- Scalars Example
- Booleans and Numbers Example
- Objects and Arrays Example
- camelCase to kebab-case
- Using compact to pass variables directly through
Upgrade from 1.1.x to 2.0.0
In 2.0, the @vue
and @endvue
directives have been renamed to @inlinevue
and @endinlinevue
. The new @vue
and @endvue
directives should now be used for non-inline components.
WARNING: You'll need to make sure that you run php artisan view:clear
after upgrading
Installation
To install the Laravel Blade Vue Directive, simply run composer require jhoff/blade-vue-directive
in a terminal, or if you prefer to manually install you can the following in your composer.json
file and then run composer install
from the terminal:
For Laravel 5.5 and later, the package will automatically register. If you're using Laravel before 5.5, then you need to add the provider to the providers array of config/app.php
.
Usage
The Laravel Blade Vue Directive was written to be simple and intuitive to use. It's not opinionated about how you use your vue.js components. Simply provide a component name and (optionally) an associative array of properties.
Basic Example
Using the vue directive with no arguments in your blade file
Renders in html as
Note that the contents between the start and end tag are optional and will be provided as slot contents. To use an inline-template, use the @inlinevue
directive instead:
Renders in html as
Scalars Example
Using the vue directive with an associative array as the second argument will automatically translate into native properties that you can use within your vue.js components.
Renders in html as
Then, to use the properties in your vue.js component, add them to props
in your component definition. See Component::props for more information.
Booleans and Numbers Example
Properties that are booleans or numeric will be bound automatically as well
Renders in html as
Objects and Arrays Example
The vue directive will automatically handle any objects or arrays to make sure that vue.js can interact with them without any additional effort.
Renders in html as
Notice that the object is json encoded, html escaped and the property is prepended with :
to ensure that vue will bind the value as data.
To use an object property in your component, make sure to make it an Object
type:
camelCase to kebab-case
If you provide camel cased property names, they will automatically be converted to kebab case for you. This is especially useful since vue.js will still work with camelCase variable names.
Renders in html as
Just make sure that it's still camelCased in the component props definition:
Using compact to pass variables directly through
Just like when you render a view from a controller, you can use compact to pass a complex set of variables directly through to vue:
Renders in html as
Then in vue, make sure to define all of your properties: