Vue3开发新范式,不用`ref/reactive`,不用`ref.value`

什么是Cabloy-Front?

Cabloy-Front 是一款支持 IOC 容器的 Vue3 框架。不用ref/reactive,不用ref.value,不用pinia

与UI库的配合

Cabloy-Front 可以搭配任何 UI 库使用,并且内置了几款 UI 库的项目模版,便于开箱即用,包括:

  • antdv
  • element-plus
  • quasar
  • vuetify

特性

Cabloy-Front 为 Vue3 引入了以下鲜明特征:

  • 不用ref/reactive:因为在大多数场景下,不需要使用 ref 和 reactive
  • 不用ref.value:因为在 Cabloy-Front 中定义响应式变量更加直观,不再需要 ref 语义
  • 不用pinia:因为 Cabloy-Front 提供了 IOC 容器,可以更加灵活的定义和使用全局对象

动图演示

演示:不用ref/reactive,不用ref.value

1. 定义响应式状态

typescript 复制代码
@Local()
export class MotherPageCounter extends BeanMotherPageBase {
  counter: number = 0;

  inrement() {
    this.counter++;
  }

  decrement() {
    this.counter--;
  }
}

2. 使用响应式状态

typescript 复制代码
@Local()
export class RenderPageCounter extends BeanRenderBase {
  render() {
    return (
      <div>
        <div>counter(ref): {this.counter}</div>
        <button onClick={() => this.inrement()}>Inrement</button>
        <button onClick={() => this.decrement()}>Decrement</button>
      </div>
    );
  }
}

演示:依赖注入

1. 逻辑抽离

counter逻辑抽离出来,创建一个Counter Bean

typescript 复制代码
@Local()
export class LocalCounter extends BeanBase {
  counter: number = 0;

  inrement() {
    this.counter++;
  }

  decrement() {
    this.counter--;
  }
}

2. 在组件中注入并使用

typescript 复制代码
@Local()
export class MotherPageCounter extends BeanMotherPageBase {
  @Use()
  $$counter: LocalCounter;
}
typescript 复制代码
@Local()
export class RenderPageCounter extends BeanRenderBase {
  render() {
    return (
      <div>
        <div>counter(ref): {this.$$counter.counter}</div>
        <button onClick={() => this.$$counter.inrement()}>Inrement</button>
        <button onClick={() => this.$$counter.decrement()}>Decrement</button>
      </div>
    );
  }
}

框架已开源: https://github.com/cabloy/cabloy-front

相关推荐
那年窗外下的雪.21 小时前
鸿蒙ArkUI布局与样式进阶(十五)—— 模块化 · 自定义组件 · 泛型机制深度解析
javascript·华为·typescript·harmonyos·鸿蒙·arkui
guangzan1 天前
React 状态管理的“碎片化”
typescript·zustand
慢知行1 天前
从 0 到 1 搭建 Vite+Vue3+TS 工程模板:能上手操作的指南
前端·vue.js·typescript
濮水大叔1 天前
VonaJS业务抽象层: 验证码体系
typescript·nodejs·nestjs
IT教程资源C1 天前
(N_158)基于微信小程序学生社团管理系统
mysql·vue3·前后端分离·社团小程序·springboot社团小程序
H_HX1262 天前
vue3 - 图片放大镜效果实现
前端·vue.js·vue3·vueuse·图片放大镜
锦瑟弦音2 天前
2048游戏开发笔记4 & 音效 cocos3.8.7
笔记·typescript·cocos2d
IT教程资源2 天前
N-158基于微信小程序学生社团管理系统
vue3·uniapp·前后端分离·springboot社团·社团小程序
小码编匠3 天前
Three.js 遇上 Vue3 开发现代化 3D 可视化编辑系统
vue.js·typescript·three.js