码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 开发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 容器,可以更加灵活的定义和使用全局对象

    动图演示

    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()}>Inrementbutton>
            <button onClick={() => this.decrement()}>Decrementbutton>
          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()}>Inrementbutton>
            <button onClick={() => this.$$counter.decrement()}>Decrementbutton>
          div>
        );
      }
    }
    

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

  • 相关阅读:
    415. 字符串相加
    java毕业设计网上汽车售票系统源码+lw文档+mybatis+系统+mysql数据库+调试
    Centos7安装mysql
    SpringBoot 20 Shiro授权的实现和整合Thymeleaf
    Ubuntu20.04 从头到尾完整版安装anaconda、cuda、cudnn、pytorch、paddle2.3成功记录
    [ C++ ] STL_stack(栈)queue(队列)使用及其重要接口模拟实现
    【Python学习笔记】Python近期总结
    【Java集合类】之Map集合的特点及使用
    前端权限管理方案之精确到按钮级别
    【从零开始学习 SystemVerilog】7.2、SystemVerilog 类—— Class Handles 和 Objects(句柄和对象)
  • 原文地址:https://www.cnblogs.com/zhennann/p/18195691
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号