基于vuejs v3.0中的类组件的vuejs项目会发生什么? [英] what will happen for vuejs projects based on class components in vuejs v3.0?

查看:364
本文介绍了基于vuejs v3.0中的类组件的vuejs项目会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的vuejs项目升级为基于类组件的打字稿,但是我读了vue问题的

i wanna upgrade my vuejs project to typescript based on class components, but i read in vue issue's https://github.com/vuejs/rfcs/pull/17#issuecomment-494242121 :

更新:正在删除Class API提案.

Update: the Class API proposal is being dropped.

那么现有的基于类组件的项目会发生什么呢? 更重要的是,根据本文: https://alligator.io/vuejs/using-typescript-with-vue/表示

so what will happen to existing class component-based projects? and more important, based on this article: https://alligator.io/vuejs/using-typescript-with-vue/ which says

由于我们没有使用类样式的语法,因此请使用as关键字 将数据声明为数据类型.

Since we are not using the class-style syntax, you use the as keyword to declare data as a data type.

在vue3.0中这种使用打字稿的方式安全吗?

is this way of using typescript safe in vue3.0?

推荐答案

当前没有官方的基于类的API. RFC即将添加一个,但由于此处讨论的原因而被删除.

Currently there is no official class-based API. RFC was about adding one but was dropped for the reason discussed there.

现有项目正在使用 vue-class-component 库,该库建立在官方的基于对象的组件API.这应该在3.0中继续起作用(因为基于对象的组件API保持不变),但存在相同的缺点此处是维护者的一则评论,宣布支持Vue. 3.

Existing projects are using vue-class-component library which builds on top of official object-based component API. This should continue to work in 3.0 (because object-based component API stays the same) but suffer from the same drawbacks mentioned in the RFC. Here is a comment from maintainer declaring support for Vue 3.

第二篇链接文章使用的是不带vue-class-component的TypeScript-没有类,只有常规的基于对象的组件API + TypeScript类型注释.是的,这将在3.0版本中起作用

Second linked article is using TypeScript without vue-class-component - no classes, just regular object-based component API + TypeScript type annotations. So yes, this will work in 3.0

但是,如果您现在开始在Vue中使用TypeScript,我强烈建议您看看 composition-api

However if you are starting with TypeScript in Vue now, I would strongly recommend to take a look at the new composition API which will be added in 3.0. It's an official API (not a library) and has many benefits compared to any existing solution. You can even use it now thanks to composition-api

这篇关于基于vuejs v3.0中的类组件的vuejs项目会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆