简体   繁体   English

我是否必须在 Vue 3 中使用组合 API,或者我仍然可以按照“Vue 2”的方式做事吗?

[英]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.

相关问题 为什么我在使用 vue-sfc-rollup 构建的 Vue 2 组件库中使用 Vue 2 Composition API 时会出错? - Why do I get an error when I use the Vue 2 Composition API in a Vue 2 component library built with vue-sfc-rollup? 在 vue 3 中使用组合 api 的插件更简单 - Easier way to use plugins with the composition api in vue 3 Vue 3 vue-国际化。 如何在应用程序(.vue 文件)之外使用 $t(t)? 作文 API - Vue 3 vue-i18n. How to use $t(t) outside the app(.vue files)? Composition API 在 vue api 组合中,我应该在反应式中使用 ref 吗? - In vue api composition should I use ref inside reactive? 如何在 Vue 3 中跟踪组合为 APi 的外部文件中的数据更改 - How do I track data changes in external file with composition APi in Vue 3 如何使用 Vuex 命名空间模块和 Vue 组合 API 获得多个操作和 state? - How do I get multiple actions and state with Vuex namespaced modules and the Vue Composition API? 如何使用组合清除 Vue3 中的反应数组? - How do I clear a reactive array in Vue3 using composition? 如何在 Vue 3 的组合 API 中引用设置 function 中的图像? - How do I reference an image inside the Setup function in the Composition API in Vue 3? vue3 我可以组合 api 参考类型吗? - vue3 can I cange composition api ref type? 如何在 Vue 3 Composition API 中的手表 function 中使用处理程序 _.throttle function? - How can I use handler _.throttle function within watch function in Vue 3 Composition API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM