Vue 3.0 features | New Features in VueJS version 3

    Sep 24, 202010 min read8750 viewsUpdated:Nov 27, 2024
    Vue 3.0 features | New Features in VueJS version 3

    Vue 3.0 has been officially launched on the 18th of September. Vue 3.0 is a planned upgrade to the Javascript framework that is used for building web user Interface. The project was currently in beta or Release candidate status in early spring. It moved towards the general release with the stabilization of the Vue 3 core. The team has already published the Vue 3.0 docs and a migration guide to let you know what has changed. 

    What's new in Vue 3.0?

    Vue 3.0 is expected to be smaller, more maintainable, and easier to use, which can be migrated from the existing Vue 2 applications to version 3.0 to use the latest features. Vue framework has etched its place in the market and into the hearts of many web developers in the last couple of years.  With a lot of exciting features, Vue team has worked on some major additions and improvements  that culminates in a beta version of Vue 3, making its way to the final release.  

    In this article we will walk you through the new features of Vue 3.0, its updates, setups, and a few more information about the release process and your first steps with Vue 3.0. 

    Vue 3.0 Features

    In the last few years, there has been changes in the landscape of Vuejs development. The community has grown from a small upstart to a fully-fledged SPA library. 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.

    Composition API

    The components in Vue 2.0, were created with the object-based Options API. 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. It can be seen as a new way of developing components which is a stark change to the Options API. The Composition API was launched as a plugin a few months back however in Vue 3.0 it doesn't have to be installed like a plug-in like before. It is now in-built into the package and can be used without any additional setup. 

    The main reason behind the formulation of Composition API is to improve the quality of the code by allowing decouple features of the logic. As opposed to Vue 2 where developers rely on extending the object and then share logic, Vue 3 allows sharing features via standard JavaScript/TypeScript patterns instead of inventing new ones. This helps in seeing the features as they were added. In addition to this, the Composition API makes it easier for the types to infer, that supports the typescript in a better way.

    Vue 3.0 lets you build components and allows the new API to co-exist with the Options API, without replacing it. Composition API provides more flexible code organization and logic reuse capabilities along with other improvements. Codes are easily readable, organized better when written with the Composition API.

    Better TypeScript support

    With the advent of Composition API, the internal functions are used as expected in JavaScript which allows for much better TypeScript support. It results in better type inferences with bindings returned from setup along with props declarations used to infer types. TypeScript definitions benefit JavaScript users largely, making the Component code by TypeScript and JavaScript look identical.

    The typescript aids in enhancing the maintainability of the Vue codebase and makes it easier for developers to contribute. It is a frequent choice for large projects because of its popularity. Having Vue 3 internals in TypeScript helps to benefit fully from Vue’s TypeScript with the usual code support available in modern IDEs such as Visual Studio Code or WebStorm. Since TypeScript’s Vue code is 90% JavaScript, JavaScript users also benefit from code intelligence features with modern IDEs.

    Reactivity

    In Vue 2.0 the reactivity worked in a way that wasn't exposed to the developer. The details are hidden causing more confusion than it should have. This Vue 3.0 feature came to the rescue by supporting several ways of wrapping objects to ensure that they are reactive.  They can be wrapped with a ref function for scalar types. This helps in reading and writing the property directly (if necessary) with .value:

    const name = ref("Shawn");
    const allCaps = computed(() => {name.value.toUpperCase()});

    For templates, objects that are are unwrapped by default need to use the .value as opposed to the ones that are wrapped:

    <template>
    <div>
    <label>Name: </label>
    <input v-model="name">
    <div>{{ name }}</div>
    <div>{{ allCaps }}</div>
    <button @click="addCharacter">Add</button>
    </div>
    </template>

    Multiple root elements (template syntax )

    Earlier in Vue 2, the template tag could only take one root element. Even with just two <p> tags, are to be enclosed within a <div> tag for it to work. With Vue 3.0 this restriction of having a root element is not there anymore. The template syntax is valued by the segments of the Vue community that go well with the HTML and CSS. These templates offer performance optimizations when compiling into optimized render functions to leverage a data structure for diffing purposes. A template bifurcates static nodes from dynamic nodes keeping track of parts and their dependencies in a specific data structure. While creating a template the code used in Vue 2.0 is similar as Vue 3.0.  Vue’s support for fragments is useful as it renders components in a list to remove unnecessary wrapper div elements. It looks like this;

    class Columns extends React.Component {
    render() {
    return (
    <React.Fragment>
    <td>Hello</td>
    <td>World</td>
    </React.Fragment>
    );
    }}

    The fragment will not be rendered in a DOM tree despite being a normal DOM which helps in binding component functionality into a single element without creating a redundant DOM node. 

    Multiple V-models

    V- model is a directive that is used for two-way binding on a given component. It is mostly used with form elements and custom components.

    A well known V- model  from the form elements looks like this: 

    <input v-model="property />

    But the question is how do we use it in every component?

    Under the hood, It can be modified from the inside of a component by passing a reactive property and listening to input events.

    Let's rewrite the above example to see how the syntax will effect below:

    <input
    v-bind:value="property"
    v-on:input="property = $event.target.value"
    />

    A  V-model directive can aid in syntactic suger for a  two-way binding in our components. Unfortunately, you can only have one v-model per component. This is one of the features of Vue 3.0. It lets you give v-model properties names without any restrictions, unlike Vue 2.0.

    Suspense

    Suspense is a new feature of Vue 3.0 which helps in rendering a default component until the main component fetches the data. The async operations that are used to fetch data from the server is done by the Suspense. It can be used in individual parts of the template or the whole template. It is the idea that is derived and adapted from the React ecosystem to suspend your component rendering.

    Portals

    Portals are special components that are used for rendering certain content outside the current component. Portals are a top-notch way for rendering children into a DOM node, existing outside the DOM hierarchy of the parent component. Portals are an efficient way of handling modals, popups, and components that are generally meant to appear on top of the page. This Vue 3.0 feature of Vue 3.0 ensures that none of the host component CSS rules are going to affect the component you want to display and then relieve you from doing nasty hacks with z-index. For this, every portal needs to be specific about their target destination where portal content will be rendered.

    contact us


    Other Minor Vue v3.0 Features and Improvements:

    Faster

    Compile-time hints have been added to the Vue 3.0 features to reduce runtime overhead. This helps avoid unnecessary condition branches and re-renders. You can expect upto 80 percent faster component instance initialization and half the memory usage.

    Smaller

    Vue 3 is smaller and tree shaking-friendly. Tree shaking shakes off the unused code. The core runtime has shrunk from ~20kb in size to ~10kb, gzipped. The global APIs help reduce the size of the Vue bundle and the template code.

    Coherence

    Vue 3.0 has libraries like Vue Router and test-utils along with a custom renderer API  that helps in creating renderers for mobile or other host environments.

    New Custom directives API

    Custom directives API are updated in Vue 3.0 features to better align with the components' lifecycle. This change makes the API easier and more intuitive that helps the newcomers to understand the core structure.

    Migration to Vue 3.0 from Vue 2.0

    The last release for version 2 backports compatible Vue 3 features as well as adds deprecation warnings for breaking changes. This new version of Vue 3.0 will be available as long-term support and will get security updates for 18 months. For the beta version, there is a migration guide however, there will be a compatibility build for Vue 3.0. A command-line migration tool that is available will help you to automatically migrate as far as possible and notify where you will need to upgrade manually.

    Conclusion

    With the impressive features, there is a ton to look forward to with Vue 3.0. Since it is not linked to a corporation, it is community approved and developed. Over the years it had picked up the momentum. The Vue developer community strived hard to better serve their needs. With the growth of the Vue, the community has led to the diversification of the framework. This led every VueJS development company to start observing the development of Vue and dealing with software at scale. From distinguished beginners to back-end engineers,  everyone knows where to go looking for a front-end solution.

    Also Check out our Article: Comparison Between Angular Vs React Vs Vue

    24
    Share
    Hire Offshore Developers
    Hire Offshore Developers
    Get access to expert skills, cost-effective solutions, and custom support for your projects with our offshore dedicated teams.
    Hire now

    Related articles

    This website uses cookies to analyze website traffic and optimize your website experience. By continuing, you agree to our use of cookies as described in our Privacy Policy.