定制 jhoff/blade-vue-directive 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jhoff/blade-vue-directive

Composer 安装命令:

composer require jhoff/blade-vue-directive

包简介

Vue directive for Laravel Blade

README 文档

README

Laravel Blade Vue Directive provides blade directives for vue.js single file and inline template components.

Latest Stable Version Total Downloads MIT License Build Status Code Coverage Scrutinizer Code Quality

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:

{
    "require": {
        "jhoff/blade-vue-directive": "2.*"
    }
}

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.

  'providers' => [
    // ...
    Jhoff\BladeVue\DirectiveServiceProvider::class,
    // ...
  ],

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

    @vue('my-component')
        <div>Some optional slot content</div>
    @endvue

Renders in html as

    <component v-cloak is="my-component">
        <div>Some optional slot content</div>
    </component>

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:

    @inlinevue('my-component')
        <div>Some inline template content</div>
    @endinlinevue

Renders in html as

    <component inline-template v-cloak is="my-component">
        <div>Some inline template content</div>
    </component>

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.

    @vue('page-title', ['title' => 'Welcome to my page'])
        <h1>@{{ title }}</h1>
    @endvue

Renders in html as

    <component v-cloak is="page-title" title="Welcome to my page">
        <h1>{{ title }}</h1>
    </component>

Then, to use the properties in your vue.js component, add them to props in your component definition. See Component::props for more information.

    Vue.component('page-title', {
        props: ['title']
    });

Booleans and Numbers Example

Properties that are booleans or numeric will be bound automatically as well

    @vue('report-viewer', ['show' => true, 'report' => 8675309])
        <h1 v-if="show">Report #@{{ report }}</h1>
    @endvue

Renders in html as

    <component v-cloak is="report-viewer" :show="true" :report="8675309">
        <h1 v-if="show">Report #{{ report }}</h1>
    </component>

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.

    @vue('welcome-header', ['user' => (object)['name' => 'Jordan Hoff']])
        <h2>Welcome @{{ user.name }}!</h2>
    @endvue

Renders in html as

    <component v-cloak is="welcome-header" :user="{&quot;name&quot;:&quot;Jordan Hoff&quot;}">
        <h2>Welcome {{ user.name }}!</h2>
    </component>

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:

    Vue.component('welcome-header', {
        props: {
            user: {
                type: Object
            }
        }
    });

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.

    @vue('camel-to-kebab', ['camelCasedVariable' => 'value']])
        <div>You can still use it in camelCase see :) @{{ camelCasedVariable }}!</div>
    @endvue

Renders in html as

    <component inline-template v-cloak is="camel-to-kebab" camel-cased-variable="value">
        <div>You can still use it in camelCase see :) {{ camelCasedVariable }}!</div>
    </component>

Just make sure that it's still camelCased in the component props definition:

    Vue.component('camel-to-kebab', {
        props: ['camelCasedVariable']
    });

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:

    <?php list($one, $two, $three) = ['one', 'two', 'three']; ?>
    @vue('compact-variables', compact('one', 'two', 'three'))
        <div>Variables are passed through by name: @{{ one }}, @{{ two }}, @{{ three }}.</div>
    @endvue

Renders in html as

    <component inline-template v-cloak is="compact-variables" one="one" two="two" three="three">
        <div>Variables are passed through by name: {{ one }}, {{ two }}, {{ three }}.</div>
    </component>

Then in vue, make sure to define all of your properties:

    Vue.component('compact-variables', {
        props: ['one', 'two', 'three']
    });

jhoff/blade-vue-directive 适用场景与选型建议

jhoff/blade-vue-directive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.74k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2017 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「blade」 「Vue.js」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jhoff/blade-vue-directive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jhoff/blade-vue-directive 我们能提供哪些服务?
定制开发 / 二次开发

基于 jhoff/blade-vue-directive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-24