您现在的位置是:首页 > 文章详情

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

日期:2024-05-16点击:291

什么是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 容器,可以更加灵活的定义和使用全局对象

动图演示

No ref/reactive

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

1. 定义响应式状态

 @Local() export class MotherPageCounter extends BeanMotherPageBase { counter: number = 0; inrement() { this.counter++; } decrement() { this.counter--; } } 

2. 使用响应式状态

 @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

 @Local() export class LocalCounter extends BeanBase { counter: number = 0; inrement() { this.counter++; } decrement() { this.counter--; } } 

2. 在组件中注入并使用

 @Local() export class MotherPageCounter extends BeanMotherPageBase { @Use() $$counter: LocalCounter; } 
 @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

原文链接:https://www.oschina.net/news/292691/vue3-cabloy-front
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章