[英]Do I have to use the Composition API in Vue 3, or can I still do things the "Vue 2" way?
Is it possible to install Vue 3, but still do things the "Vue 2" way?是否可以安装 Vue 3,但仍以“Vue 2”方式进行操作? In other words, I see that Vue 3 has the new Composition API, but is that optional or the required way of doing things in Vue 3?
换句话说,我看到 Vue 3 有新的组合 API,但在 Vue 3 中这是可选的还是必需的做事方式?
For some reason, I was thinking that Vue 3 still allowed you to do things the Vue-2 way, using the Options API instead.出于某种原因,我认为 Vue 3 仍然允许您以 Vue-2 的方式做事,而是使用选项 API。 Is that not the case?
不是这样吗? Thanks.
谢谢。
Vue 3 does not require using the Composition API. The Options API is still available and will not be removed, as explained by two Vue core team members: Vue 3 不需要使用组合 API。选项 API 仍然可用,不会被删除,正如两位 Vue 核心团队成员所解释的:
Thorsten Lünborg in Vue 3: Data down, Events up (19-MAY-2020) : Vue 3 中的Thorsten Lünborg :数据下降,事件上升(2020 年 5 月 19 日) :
IMPORTANT: The composition API is additive, it's a new feature, but it doesn't and will not replace the good ole “Options API” you know and love from Vue 1 and 2. Just consider this new API as another tool in your toolbox that may come in handy in certain situations that feel a little clumsy to solve with the Options API.
重要提示:组合 API 是附加的,它是一个新功能,但它不会也不会取代您从 Vue 1 和 2 中了解和喜爱的好“Options API”。只需将这个新的 API 视为您工具箱中的另一个工具在某些情况下,使用选项 API 解决起来有点笨拙,这可能会派上用场。
Ben Hong in Enjoy the Vue #48: "New in Vue 3: The Composition API" (19-JAN-2021) : Ben Hong在享受 Vue #48 中:“Vue 3 中的新功能:组合 API” (2021 年 1 月 19 日) :
[00:01:03]
T: Yeah.[00:01:03]
T:是的。 Well, the first thing I remember hearing was that it was replacing the options API.好吧,我记得听到的第一件事是它正在替换选项 API。
[00:01:08]
BH: Big disclaimer.[00:01:08]
BH:重要的免责声明。 That isn't happening.那没有发生。 Big disclaimer.
大免责声明。
...
[00:09:10]
BH: [...] this is not something you need to go and rewrite your app in. [...] the composition API is not like, drop the options do composition.[00:09:10]
BH: [...]这不是您需要 go 并重写您的应用程序的东西。 [...]组合 API 不像,删除选项进行组合。 It's an additive thing that when you have a problem that it can solve, it's really great for that.这是一个附加的东西,当你遇到它可以解决的问题时,它真的很棒。
An early RFC for the Composition API had only considered deprecating the Options API:组合 API 的早期 RFC只考虑弃用选项 API:
A previous draft of this RFC indicated that there is the possibility of deprecating a number of 2.x options in a future major release, which has been redacted based on user feedback.
此 RFC 的先前草案表明,有可能在未来的主要版本中弃用许多 2.x 选项,这些选项已根据用户反馈进行了编辑。
The Vue docs also confirm this: Vue 文档也证实了这一点:
Will Options API be deprecated?
选项 API 会被弃用吗?
No, we do not have any plan to do so.
不,我们没有任何计划这样做。 Options API is an integral part of Vue and the reason many developers love it.
Options API 是 Vue 不可或缺的一部分,也是许多开发人员喜欢它的原因。 We also realize that many of the benefits of Composition API only manifest in larger-scale projects, and Options API remains a solid choice for many low-to-medium-complexity scenarios.
我们还意识到组合 API 的许多好处只体现在大型项目中,而选项 API 仍然是许多中低复杂度场景的可靠选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.