定制 vikseriq/vuelab 二次开发

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

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

vikseriq/vuelab

Composer 安装命令:

composer require vikseriq/vuelab

包简介

PHP loader for Vue Single File Components

README 文档

README

It's tiny tool that helps to integrate Vue (v.2) with all reactivity benefits to almost every PHP project on any PHP hosting – without need of heavy-weight loaders like webpack/rollup nor gulp/require.js.

Also available as WordPress plugin: just drop in /wp-content/plugins folder.

Vue components composes with vuer utility and injects with simple html container + new Vue vueLauncher technique.

Additionally it uses lessphp for processing styles written in less.

Note that Vue 3, ES6/module exports, template languages, loading by src and so on not supported – loader do not process nor evaluate js on server side, only composing *.vue into valid ES5 scripts and boot instances.

Template compilation relies on Vue built-in template compiler, so you must use full version of vue.js lib, not runtime-only.

Usage

  1. Clone this repo – or load via composer:
composer require vikseriq/vuelab
  1. Include vuelab.php – or use composer autoload.

  2. Provide path to dir with Vue single file components. Or drop some into /vuelab/components.

  3. Register components – just by typing component names.

  4. Place somewhere html element with class js-v-scope – it will indicate vuelab to start Vue instance it this container.

  5. And call vuelab_inject(). Now your PHP page become a first-class Vue app.

Assume that we have app.vue that loads todo-list.vue with todo.vue inside. Drop vuelab and create index.php looking like:

include '/vuelab/vuelab.php';

vuelab_setup(__DIR__, ['app', 'todo-list', 'todo']);

vuelab_append('<div class="js-v-scope"><app /></div>');

vuelab_inject();

That's all.

Usage on WordPress

  1. Add plugin to Wordpress: via upload or copy to plugins dir.

  2. Enable plugin from Plugins page – it will hook automatically.

  3. Just use it: register components and their placeholders on desired page areas.

For example, place foo.vue inside your template folder and add in functions.php:

// register component located in current path named foo.vue
vikseriq\vuelab\vuelab_setup(__DIR__, ['foo']);
// register placement for `foo` component - it will placed where `vuelab_inject` executed, in this case - at footer
vikseriq\vuelab\vuelab_append('<div class="js-v-scope"><foo /></div>');
// optionally: enable less styles compilation
vikseriq\vuelab\VueLab::$use_less = true;
<template>
  <div class="foo">Hello from Vue <span>{{ createdAt }}</span></div>
</template>
<script>
Vue.component('foo', {
  template: template, // ! it allows to pass template inside component
  data: function () {
    return {
      createdAt: new Date().toLocaleTimeString()
    }
  }
})
</script>
<style lang="less">
// feel free to use less here
@justOrange: #fc0;

.foo {
  display: block;
  margin: 1rem auto;
  padding: 1rem;
  width: fit-content;
  // sample use of less variables
  border: 3px outset @justOrange;
 
  // ... and nesting
  span {
    font-style: italic;
  }
}
</style>

Then on the very bottom of pages will be foo component with greeting and current page loading time.

Documentation

Vuelab

Vuelab::inject

Returns HTML string with Vue components, styles and launcher.

  1. Composes script+template bundle with every component via vuer.

  2. Wrap bundle in js function and bind execution on document.vueReady event to prevent evaluation before Vue and vueLauncher is ready.

  3. Appends vueLauncher code with trimmed space and comments.

  4. Process bundle styles.

  5. If \VueLab::$use_less is set – load less compiler and process styles.

  6. Appends rest of html added via \VueLab::append.

Vuer – load Vue SFC with PHP

Vuer used to convert *.vue files to browser-executable <script>

Inspired by requirejs-vue technique.

VueLauncher – make a Vue instance anywhere

VueLauncher helps boot Vue instance on any html container, by default used selector .js-v-scope.

WordPress plugin

Install by uploading archive with this repos or by using awesome GitHub Updater plugin.

When \VueLab::$wp_enqueue_vue flag is set, Vue wp_enqueue_script-ed as vue from path specified in \VueLab::$wp_vuejs_path. Obviously, for better loading time and use with cache/packer plugins provide path to local copy of vue.min.js.

Things to do

[+] Sample project.

[_] Pass variables (like string translations) to Vue component via __v on build time.

[+] Make Vuelab available as Composer package.

License

MIT © 2020 - present, vikseriq

vikseriq/vuelab 适用场景与选型建议

vikseriq/vuelab 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 vikseriq/vuelab 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-09