All Projects → riverskies → laravel-vue-component

riverskies / laravel-vue-component

Licence: MIT license
A Blade directive to ease up Vue workflow for Laravel projects

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-vue-component

vue-data-loading
Another component for infinite scroll and pull down/up to load data.
Stars: ✭ 63 (+231.58%)
Mutual labels:  vue-components
v-owl-carousel
🦉 VueJS wrapper for Owl Carousel
Stars: ✭ 46 (+142.11%)
Mutual labels:  vue-components
vue-hooks-form
Building forms with vue composition API.
Stars: ✭ 131 (+589.47%)
Mutual labels:  vue-components
laravel-sms
Laravel 贴合实际需求同时满足多种通道的短信发送组件
Stars: ✭ 67 (+252.63%)
Mutual labels:  laravel-5-package
okeedesign-mobile-vue
High Performance, Flexiable Configuration, Various Components
Stars: ✭ 139 (+631.58%)
Mutual labels:  vue-components
rails-vue-components-example
Ruby on Rails with vue.js single-file components example.
Stars: ✭ 20 (+5.26%)
Mutual labels:  vue-components
vue-skeleton-loader
A simple and easily customizable skeleton loader plugin for you Vue application.
Stars: ✭ 74 (+289.47%)
Mutual labels:  vue-components
vectre
Most complete implementation of Spectre.css on Vue.js
Stars: ✭ 63 (+231.58%)
Mutual labels:  vue-components
vue-cirrus
Vue components for the Cirrus CSS framework.
Stars: ✭ 43 (+126.32%)
Mutual labels:  vue-components
sweetalert
Laravel 5 Package for SweetAlert2. Use this package to easily show sweetalert2 prompts in your laravel app.
Stars: ✭ 28 (+47.37%)
Mutual labels:  laravel-5-package
ignore
🔥修炼内功,无招胜有招。 ---个人博客
Stars: ✭ 27 (+42.11%)
Mutual labels:  vue-components
Different-UI
✨ A Vue.js 3 UI Library — a Toy
Stars: ✭ 62 (+226.32%)
Mutual labels:  vue-components
vue-on-rails
Easy way to mount/destroy Vue.js components with Ruby on Rails and Turbolinks 5
Stars: ✭ 17 (-10.53%)
Mutual labels:  vue-components
vue-flexmonster
Vue Module for Flexmonster Pivot Table & Charts
Stars: ✭ 16 (-15.79%)
Mutual labels:  vue-components
vue3-docs
vue中文社区,vue3 中文文档
Stars: ✭ 180 (+847.37%)
Mutual labels:  vue-components
vstx-data-table
A data table component for the Vue Stacks Ecosystem
Stars: ✭ 34 (+78.95%)
Mutual labels:  vue-components
vue-cli-plugin-quasar
Quasar Framework Vue CLI plugin
Stars: ✭ 66 (+247.37%)
Mutual labels:  vue-components
vue-mui
Mobile UI elements for Vue 2.0
Stars: ✭ 16 (-15.79%)
Mutual labels:  vue-components
Oasis
🍃 UI framework based on [email protected]. (English document is coming soon)
Stars: ✭ 29 (+52.63%)
Mutual labels:  vue-components
vue-drag-zone
Drag Zone component for @vuejs
Stars: ✭ 127 (+568.42%)
Mutual labels:  vue-components

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:

$ composer require riverskies/laravel-vue-component

If you're running Laravel 5.4 or earlier, add the service provider to your config/app.php file:

Riverskies\Laravel\VueComponent\VueComponentServiceProvider::class,

Usage

Wrap your yield block in your layout file with the new directive:

<div id="app">
    @vue($component)
        @yield('content')
    @endvue
</div>

If you have $component variable set on your view...

return view('pages.home', ['component' => 'homepage']);

...the content will be wrapped within a dynamic Vue component:

<component is="homepage" inline-template v-cloak>
    <!-- yielded content -->
</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:

import Homepage from './pages/homepage.js';

const app = new Vue({
    el: '#app',
    components: { Homepage }
});

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:

return view('pages.contact', ['component' => 'contact']);

In your pages.contact.blade file (note the wrapping <div> and the escaped @{{ ... }} syntax):

@section('content')
    <div class='contact-page'>
        <h1>Contact us</h1>
        
        <ul class="errors" v-if="errors.length > 0">
            <li v-for="error in errors">@{{ error }}</li>
        </ul>
        
        <form @submit.prevent='submitForm'>
            <input v-model="email"/>
            <textarea v-model="message">@{{ message }}</textarea>
            <button type='submit'>Submit</button>
        </form>
    </div>
@endsection

In your pages/contact.js file:

export default {
    data() {
        return {
            email: '',
            message: '',
            errors: []
        }
    },
    methods: {
        submitForm() {
            // your code to verify/send form data
        }
    }
}

And your main app.js file to be like this:

import Contact from './pages/contact.js';

const app = new Vue({
    el: '#app',
    components: { Contact }
});

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 controller method
return view('welcome', [
    'component' => [
        'is' => 'contact',
        'data' => [
            'email' => '[email protected]'
        ]
    ]
]);

In your pages/contact.js file:

export default {
    props: ['data'],
    data() {
        return {
            email: '',
            message: '',
            errors: [],
            ssData: null
        }
    },
    created() {
        // you must evaluate passed through data!
        this.ssData = eval(this.data);
        
        this.email = this.ssData.email;
    },
    methods: {
        submitForm() {
            // your code to verify/send form data
        }
    }
}

This method can be used to send through data from the backend directly.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].