vue2升级vue3:class component的遗憾
在vue2,class 写法真的非常爽
import { Component as tsc } from 'vue-tsx-support';
import { Component, Watch } from 'vue-property-decorator';
import { State } from 'vuex-class';
import { debounce } from 'helpful-decorators';
@Component
export default class demo extends tsc<{}> {
@State(state => state.queryContext.timeRange) curTimeRange;
@Watch('$route.params.uid')
@debounce(500)
initPage() {
//TODO
}
}
继承
interface PageProps{}
@Component
export default class ChartWrapper extends Mixins<ChartWrapperBase>(ChartWrapperBase) implements PageProps {
//TODO
}
但是到vue3,这个class 提案被废止了——GitHub上也停留在rc1版本了,已经2年左右没有提交代码了!
试了一下 8.0.0-rc.1
把 @Component 改为 @Options ,其他都不用怎么改。单个组件能跑。全局替换了下,发现大部分多页面与组件都跑步起来——报错的太多了——对后来人劝退!
vue-class-component made sense for Vue 2.x when the TypeScript support was really bad. Currently this library provides no additional benefits, it just modifies the syntax of declaring a component. Additionally almost all users of vue-class-component are using vue-property-decorator (https://github.com/kaorun343/vue-property-decorator) which also seems abandoned.
https://github.com/vuejs/vue-class-component/issues/569#issue-1021411164
class API 被犹大 彻底 放弃
Update: the Class API proposal is being dropped.
https://github.com/vuejs/rfcs/pull/17#issuecomment-494242121
Two major reasons:
Current Class API proposal still has various edge cases / spec reliance / unresolved questions.
The new APIs proposed in Advanced Reactivity API #22 and Dynamic Lifecycle Injection #23 enables a new pattern (temporarily) named "composition functions) that can serve as a better component API than classes. Shipping both composition functions and Class API essentially results in 3 ways of doing the same thing - this is something we want to avoid at all costs. The advantage of composition functions over Classes will be discussed in more details below.
无奈,不能平滑升级,给差评——有大佬会说,react 也准备弃用 class 了
但是,对于我这类从java 出身的野生前端,确实觉得class 装饰器 更为亲切
升级事项,查看:https://levelup.gitconnected.com/from-vue-class-component-to-composition-api-ef3c3dd5fdda
至于之的实现方式,建议换 函数式 思路,比如:https://www.thisdot.co/blog/vue-3-composition-api-do-you-really-need-it
虽然网上 有很多各种的 兼容原来 vue-class-component 装饰器方案,
https://github.com/darrenrahnemoon/vue-class-api
但是还是弃坑了 ——目前基于生态原因,只能用vue
其实心里一直是 react yyds!
转载本站文章《vue2升级vue3:class component的遗憾》,
请注明出处:https://www.zhoulujun.cn/html/webfront/ECMAScript/vue3/8844.html
vue2升级vue3:class component的遗憾的更多相关文章
- vue2升级vue3:vue2 vue-i18n 升级到vue3搭配VueI18n v9
项目从vue2 升级vue3,VueI18n需要做适当的调整.主要是Vue I18n v8.x 到Vue I18n v9 or later 的变化,其中初始化: 具体可以参看:https://vue- ...
- vue2升级vue3指南(二)—— 语法warning&error篇
本文总结了vue2升级vue3可能会遇到的语法警告和错误,如果想知道怎样升级,可以查看我的上一篇文章:vue2升级vue3指南(一)-- 环境准备和构建篇 Warning 1.deep /deep/和 ...
- vue2升级vue3:Vue Demij打通vue2与vue3壁垒,构建通用组件
如果你的vue2代码之前是使用vue-class-component 类组件模式写的.选择可以使用 https://github.com/facing-dev/vue-facing-decorator ...
- vue2升级vue3:vue-i18n国际化异步按需加载
vue2异步加载之前说过,vue3还是之前的方法,只是把 i18n.setLocaleMessage改为i18n.global.setLocaleMessage 但是本文还是详细说一遍: 为什么需要异 ...
- uniapp项目vue2升级vue3简单记录
看到好多开源项目都升级了vue3,看文章说vue3性能升级很多,而且组合式api很香,遂把最近开发的自助洗车app升级下,在此记录下出现的问题. uniapp升级vue3官方指南 我是先去vue官网看 ...
- vue2升级vue3指南(一)—— 环境准备和构建篇
1.nodejs和npm 注意二者的版本,版本过低需要升级,本人升级后的版本如下: $ node -v v16.15.1 $ npm -v 8.11.0 2.package.json 和依赖升级 由于 ...
- Vue2 到 Vue3,重温这 5 个常用的 API
距离Vue3发布已经过去一年多时间了,从Vue2到Vue3是一个不小的升级,包括周边生态等.虽然目前大多数开发者们在使用的仍旧以Vue2为准,但Vue3显然是Vue开发者们未来必须面对的,而且前不久V ...
- Vue2和Vue3技术整理1 - 入门篇 - 更新完毕
Vue2 0.前言 首先说明:要直接上手简单得很,看官网熟悉大概有哪些东西.怎么用的,然后简单练一下就可以做出程序来了,最多两天,无论Vue2还是Vue3,就都完全可以了,Vue3就是比Vue2多了一 ...
- vue2和vue3生命周期的区别
概念 首先,我们了解一下"生命周期"这个词.通俗的来说,生命周期就是一个事务从出生到消失的过程.例如,一个人从出生到去世.在vue中,vue的生命周期是指,从创建vue对象到销毁v ...
- 盘点Vue2和Vue3的10种组件通信方式(值得收藏)
Vue中组件通信方式有很多,其中Vue2和Vue3实现起来也会有很多差异:本文将通过选项式API 组合式API以及setup三种不同实现方式全面介绍Vue2和Vue3的组件通信方式.其中将要实现的通信 ...
随机推荐
- C# -WebAPIOperator.cs
说明:一个用C#编写的WebAPI操作类,只写了Get Post 部分. using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System ...
- JUC并发编程学习(五)集合类不安全
集合类不安全 List不安全 单线程情况下集合类和很多其他的类都是安全的,因为同一时间只有一个线程在对他们进行修改,但是如果是多线程情况下,那么集合类就不一定是安全的,可能会出现一条线程正在修改的同时 ...
- 题解 CF916C
题目大意: 要求构造一张图,并让该图满足以下条件: 有 \(n\) 个点,\(m\) 条边. 每条边的边权范围是 \([1,10^9]\). 图中从 \(1\) 到 \(n\) 的最短路径长度是个质数 ...
- AtCoder Beginner Contest 328 (ABC328)
A. Not Too Hard 模拟. Code B. 11/11 模拟. Code C. Consecutive Description 给你一个字符串 \(S\),有 \(Q\) 次询问,每次输入 ...
- C语言实现输入的时间,屏幕显示一秒后的时间。显示格式为HH:MM:SS。
#include <stdio.h> int main() { int HH, MM, SS; scanf("%d:%d:%d",&HH,&MM,&am ...
- 【Javaweb】Servlet* | 请求重定向【🖤🖤】
请求重定向的含义 请求重定向,是指客户端给服务器发请求,然后服务器告诉客户端说.我给你一些地址,你去新地址访问,叫请求重定向(因为之前的地址可能已经废弃). 请求重定向的实现代码 请求重定向的第一种方 ...
- 利用Jdk动态代理模拟MyBatis的Mapper功能
本文将先介绍jdk动态代理的基本用法,并对其原理和注意事项予以说明.之后将以两个最常见的应用场景为例,进行代码实操.这两个应用场景分别是拦截器和声明性接口,它们在许多开发框架中广泛使用.比如在spri ...
- Redis本地安装以及使用(详细教程)
Redis 安装 Windows 下载安装 Redis默认端口:6379 整个过程如下: 1.下载连接 https://github.com/tporadowski/redis/releases Re ...
- [ARC122E] Increasing LCMs
Problem Statement We have a sequence of $N$ positive integers: $A_1,A_2,\cdots,A_N$. You are to rear ...
- [CF568E] Longest Increasing Subsequence
题目描述 Note that the memory limit in this problem is less than usual. Let's consider an array consisti ...