Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what will happen for vuejs projects based on class components in vuejs v3.0?

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 :

Update: the Class API proposal is being dropped.

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

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

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

like image 432
SeyyedKhandon Avatar asked Jan 08 '20 11:01

SeyyedKhandon


People also ask

Can I use Vue 3 or should I still use Vue 2 for a new project?

In general, Vue 3 provides smaller bundle sizes, better performance, better scalability, and better TypeScript / IDE support. If you are starting a new project today, Vue 3 is the recommended choice. There are only a few reasons for you to consider Vue 2 as of now: You need to support IE11.

What changed in Vue 3?

Other changes in Vue 3: Virtual DOM rewrite for better performance and improved TypeScript support. Native portals – now called Teleport. Fragments (virtual elements that won't be rendered in the DOM tree) More flexibility for global mounting.

How does Vue 3 reactivity work?

Vue's reactivity system works by deeply converting plain JavaScript objects into reactive proxies. The deep conversion can be unnecessary or sometimes unwanted when integrating with external state management systems (e.g. if an external solution also uses Proxies).

Does Vue reuse components?

Since components are reusable Vue instances, they accept the same options as new Vue , such as data , computed , watch , methods , and lifecycle hooks. The only exceptions are a few root-specific options like el .

What is Vue class component?

Overview Vue Class Component is a library that lets you make your Vue components in class-style syntax. For example, below is a simple counter component written with Vue Class Component:

What are the new features of VUE 3?

With version 3 on the horizon, the team has added a few supports to augment the library, simplify coding on Vue, and adopt modern techniques of Web development. Let's dig into the main new features of Vue 3.0 that will guide you through the development of Vue applications. The components in Vue 2.0, were created with the object-based Options API.

Why should I use Vue instead of HTML?

It's common for an app to be organized into a tree of nested components: This is very similar to how we nest native HTML elements, but Vue implements its own component model that allow us to encapsulate custom content and logic in each component. Vue also plays nicely with native Web Components.

What is composition API in Vue?

One of the new features of Vue 3.0 is that it has added a set of function-based APIs that is called Composition API. These APIs have been added to address issues faced by Vue 2 for very large projects. The Composition API has caused the most controversy with the Vue community.


Video Answer


1 Answers

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

Existing projects are using vue-class-component library which builds on top of official object-based component API (officially called Options API). This should continue to work in 3.0 (because Options 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.

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

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 Composition API with Vue 2 thanks to composition-api - this is plugin but plan is in place to make it official, better integrated into Vue core and maintained by Vue core team.

like image 88
Michal Levý Avatar answered Oct 08 '22 11:10

Michal Levý