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

相关推荐
AI情绪识别开源13 小时前
HFpEF 心房-心室耦联效率无创监测方向(AVCEI)
typescript·laravel·perl
凤城老人14 小时前
从 PyQt6 到 Electron:给 Edge TTS 做一个“多角色配音机“的踩坑手记
javascript·typescript·electron
zhousenshan2 天前
TypeScript 入门到精通
typescript
花旗蜕变2 天前
前端转 NestJS 全栈实践:从表单页面到微信业务系统
前端·typescript·nestjs
艺杯羹2 天前
Anthropic突袭发布Claude Code Mods!用TypeScript编写智能体中间件:告别AI误删与失控
人工智能·typescript·系统架构
陪我一起学编程4 天前
vue3笔记
前端·webpack·vue3·vite·脚手架·vue3笔记·组件式
FYKJ_20105 天前
SSM校园失物招领系统41452-计算机课程设计、毕业设计
java·vue.js·spring boot·python·mysql·typescript·spark
tiankongdeyige5 天前
游戏战斗系统学习第2篇:有限状态机 (FSM)
学习·游戏·typescript
FYKJ_20106 天前
django电影推荐系统55066-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·typescript·spark·django
进击的明明6 天前
TypeScript速通笔记(下)
前端·面试·typescript