40

Why I Chose Vue over React

 5 years ago
source link: https://www.tuicool.com/articles/hit/Z77v2yv
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
BniEruI.jpg!webyiAF7fI.jpg!web
Vue vs React

In mylast article, we made a comparison of Angular, React and Vue by building a small web application using each. That concluded with React and Vue being the champion.

In this article, I would like to share my views on why I have become a big fan of Vue. I will try to be unbiased as much as possible. So, this in my own opinionated take on the question. Here’s why.

List elements

One of the most common element in a web app is to render a list element given an array. Let’s see the syntax in Vue and React.

React

List in React

Vue

List in Vue

Now which looks more simpler, React’s jsx syntax or Vue’s html, you decide.

I prefer the cleaner vue’s syntax.

Component Skeleton Structure

Below is the basic component syntax written in both.

React Component
Vue component

Writing components should be simple with clear distinction in javascript part and html. Things look mixed up in react’s syntax (again completely my opinion).

Component Lifecycles

In React we have

  • constructor
  • componentWillMount
  • componentDidMount
  • componentWillUpdate
  • componentDidUpdate
  • render

Distinguishing between each of them becomes quite confusing for a newbie and i don’t blame them. Sheer number of lifecycles is a bit too much. Now in which lifecycle should we do an api call for fetching data.

In Vue we have

  • created
  • mounted
  • updated
  • beforeCreate
  • beforeMount
  • beforeUpdate

Simple enough and all of them make sense. Most often we have to deal with created or mounted lifecycle.

Event handling

Event handling should be very simple and straight forward since it is one of the most used feature of any javascript framework. Lets see how React and Vue handle this.

click event handling in react
click event handling in vue

Vue provides very simple syntax for handling events where as in react, using this keyword then binding this in constructor seems unnecessary for a simple click handler.

Computed properties

Before wrapping, i would like to highlight one of the awesome feature that vue provides, computed property.

Lets say we have a prop called, dollars and we have to render converted rupees in ui. This becomes very simple with computed property. Below is how we’ll use it

computer property in Vue

In my opinion, Vue is simpler than other current frameworks and thus makes the learning process easier not overwhelming. Hope you liked the article. If you did, please share a clap. Please feel free to suggest your own insights! Thanks for reading…


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK