Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

4 Things Vue.js Got Right

DZone's Guide to

4 Things Vue.js Got Right

Vue.js is the new kid on the block but has quickly become one of the most popular JavaScript frameworks. Find out why in this article.

· Web Dev Zone
Free Resource

Get deep insight into Node.js applications with real-time metrics, CPU profiling, and heap snapshots with N|Solid from NodeSource. Learn more.

Whether you’re suffering from Javascript fatigue, ES anxiety, post-webpack stress disorder or any other kind of web development malady, the last thing you probably want to do now is look at another Javascript framework.

But the focus, simplicity, and flexibility of Vue.js might just make it the hero you need. Coming a bit late to the game in 2014, Vue has had the advantage of being able to pick and choose from the best parts of its predecessors.

Note: this article was originally posted here on Medium on 2016/11/10

Focus

Vue has a narrow use case: building user interfaces for the web. The creators know that there are already plenty of libraries out there to help you iterate arrays or handle promises and HTTP requests, so you won’t find any of that duplicated in Vue.

This focus allows Vue to avoid the bloat of other frameworks. But just as importantly, the minimal surface areas of its API allows its creators to focus more on improving Vue than maintaining it.

That said, Vue does have supporting libraries like vue-router, for routing, and Vuex, a Flux-inspired library for state management. These integrate deeply with Vue but are completely optional.

Here’s a great example of Vue’s focus ethos in action: Vue creator Evan You announced recently that vue-resource, the official AJAX library for Vue, would be retired from the Vue organization. The reason: AJAX is not a problem domain requiring deep integration with Vue and the time spent bug fixing it would be better spent on more integral parts of the stack.

Simplicity

Adding Vue to your web project can be as simple as:

<script src="https://unpkg.com/vue/dist/vue.js"></script>

And you’re ready to start. No transpiling or wrestling with a bundler is required.

Vue code has simplicity built into its design. Look at this "hello world" example:

<div id="app">
  {{ message }}
</div>
<script>
new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue!'
  }
});
</script>

Even those with only a basic understanding of HTML and JS — perhaps designers and juniors on a team — can get a sense of how Vue code works. For more experienced developers, this simplicity allows immediate productivity.

If the success of jQuery is anything to go by, Vue’s standing as the simplest of the frameworks could take it a long way.

I ... really care about the approachability part of Vue, which is rooted in the belief that technology should be enabling more people to build things. Evan You, creator of Vue.js — Between The Wires

Flexibility

If you want to write a quick and easy app that will run straight from the browser, Vue has got you covered. If you want to build a more sophisticated app with ES6, JSX, separate component files, routing, bundling, etc., then Vue can deal with that too.

Vue is focused regarding what it can do for you, but not opinionated about how you do it. For example, if you have a preferred method for writing your templates, Vue lets you do it in any of these ways:

  1. Write your template in an HTML file.
  2. Write your template in a string in a JavaScript file.
  3. Use JSX in a JavaScript file.
  4. Make your template in pure JavaScript using render functions.

This flexibility makes it easy to switch to Vue because React developers, Angular developers, or developers new to JS frameworks would all find Vue’s design familiar.

Copying Competitors

A lot of what Vue is getting right is what its predecessors already got right. Just ask an Angular developer. Vue’s directives copy Angular’s right down to the syntax: to bind an input to application data in Vue you use v-model just like Angular’s ng-model.

As a relatively late mover, Vue has been able to copy what works in other frameworks and avoid what doesn’t. Vue’s reactivity system has inspiration from Elm. Vue’s template syntax is similar to Angular. In its latest version, Vue is now rocking a virtual DOM à la React.

Vue is earning its place by being a great solution if not an original one.

Get the latest Vue.js articles, tutorials and cool projects in your inbox with the Vue.js Developers Newsletter

Node.js application metrics sent directly to any statsd-compliant system. Get N|Solid

Topics:
vue.js ,javascript ,web design and web development ,front end development

Published at DZone with permission of Anthony Gore, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}