Vue 3.2
blog.vuejs.org
blog.vuejs.org
Also, I think I do prefer working with JSX versus using html templates. I prefer that close coupling of JS logic and JSX presentation.
The most appealing thing about Vue is that it seems to be more of a framework, maybe somewhere in the middle between base React/ReactDOM and Next.js.
To be quite honest, I'd probably stick with React if given the choice. My takeaway with Vue is it makes a number of choices for you out of the gate w.r.t to things like data store (Vuex) and routing (Vue-router) whereas with React you'd bolt these on yourself (i.e. mobx and found-router).
I also feel like Vue gives you many more opportunities to shoot yourself in the foot in weird and wonderful ways. For example, you can access the instance of a parent or child component without too much trouble whereas React does seem to go out of its way to prevent this.
React has a few quality of life improvements too, things like hooks (which may be in Vue now? Not sure) and being able to have components with multiple children at the root.
> you can access the instance of a parent or child component without too much trouble
$children was removed in vue3 https://v3.vuejs.org/guide/migration/children.html
> things like hooks
Vue doesn't have react style hooks, but the composition API fills a similar niche.
> being able to have components with multiple children at the root.
Vue3 seems to support this: https://v3.vuejs.org/guide/migration/fragments.html
I like de facto solutions instead of half-baked libraries that might have slight incompatability issues.
I also like the freedom and flexibility that vue offers rather than the weird guardrails that come with react.
But, with React, I rarely find myself wondering why the component isn’t re-rendering when something changes, whereas this happens frequently with Vue.
I also rarely find myself having to plan out how props will flow to state or when something needs to be a computed (or memoized) property. Things usually just kind of come together.
There are several reasons for this, but often times it comes down to either doing the wrong type of assignment that makes Vue lose its wrapper object around the property, or something to do with the way I use props as defaults for reactive state.
Which leads to another complaint - mixing props passed in to the component in the same space as the reactive state. This means the property needs a different name from the state property that it drives, it means having to mentally track which piece of data can be mutated because its state and which cannot because its a prop, and it often means wondering why your component isn’t re-rendering when your prop changes, only to finally realize you really need a computed prop or a prop watcher.
I don’t want to sound overly dramatic though. It doesn’t happen every day, it’s never prevented me from doing anything, and Vue (IMO) makes up for it in other ways like single file components with better styling options. It’s also possible I just haven’t used React enough.
But that said, in my experience, some of Vue’s magic that makes it simpler to get started with, is also what makes it trickier to work with as projects get larger.
Disclaimer: Vue 3 introduces hook like things that I haven’t tried, and perhaps make my complaints less valid.
I have a different experience though. I generally find React pretty mysterious, with very confusingly named methods, and several generations of approaches that are completely different from each other. (React Hooks changes everything...)
I used to occasionally find situations in Vue where something wouldn't re-render, but that almost never happens anymore. The main culprits are when a component never gets mounted (because it's in a v-if), or expecting reactivity before it gets mounted.
I hate the clumsiness of React, the lack of "methods" and simple event handlers, the need to be overly verbose everywhere.
I almost never use Vuex, fwiw. I find both Redux and Vuex (which apes it) are an incredibly complicated solution to the problem, and wish there was something simpler.
With composition API and Vue 3 bringing typescript support and hooks to me it's a no brainer to choose Vue.
One other thing is that I've seen people who are normally doing only backend pick up Vue in a day or 2, but React takes longer to grok. You're probably likely to find more people who have already learned React than Vue though, due to its popularity.
React also has a bigger community but I haven't felt that I was lacking when looking for Vue libraries.
React is: always right, sometimes slow
Vue is: always fast, mostly right
I prefer fixing performance bottlenecks later over having any doubt about the correctness of my view or debugging why this one property only sometimes becomes reactive. But I can see how others would feel differently.
Once you get past the fundamentals, it's just choosing the features that you like better. Vue uses HTML-based templates by default which I find better for 99% of scenarios, and can also be generated by a server-side framework which makes it easy to integrate into existing webapps without rebuilding as a complete SPA.
Reactivity is another thing that all frameworks and state management as evolved to, since it's just automating what you were manually doing anyway. Mobx and the like were early versions but the composition API in Vue 3 is probably the most polished version of this with automatic tracking that does what you expect and intuitive effects/watchers.
Vue also has official projects vs the 'unofficial' official ones for React, but that's a purely subjective preference at this point.
I'm considering a move in the opposite direction for a few reasons:
1. React Native. I can build mobile apps using Vue via Ionic Framework / Cordova / Capacitor but that ecosystem is a nightmare (esp the Cordova/Capacitor split). React Native has more extensions available and the camera related ones are considerably more featureful.
2. Libraries/widgets. Vue has widget libraries available and (multi)select fields et al work great. But when you want something more advanced - a decent calendar picker for example - I always turn up a React library that does what I want, and the Vue one doesn't. [I suspect there's compatibility issues if you use too many React widgets - gras is always greener etc]
3. Expectation that you know React. I've had clients say "we use Vue, do you know it?" but I've had 10x more say "We use React, do you know it?".
I was merely offering an objective correction to the parent comment's statement:
> It hasn’t been maintained since October 2020
When I was looking to change jobs earlier this year I spoke with a lot of recruiters and they all said companies were looking for React developers, there were zero mentions of Vue. I don’t really regret my choice of learning Vue but React would have definitely been a selling point on my resume.
Will this change in a few years? Who knows. It feels like it’s React vs everyone else and as more and more projects get built in React I suspect the difference will widen even more.
We switched our main product to Vue last year, and we couldn't be happier. And, we advertise Vue in our job postings. And, we are hiring!
I'd rather have jsx, all else being equal.
Also Vue's automatic reactivity system is fine for small websites but for large apps it turns into an impossible to follow spaghetti nightmare.
I've heard there is some pain upgrading Vue, but there is definitely pain when upgrading React.
At the moment one of our previous React projects "npm install" gives 4000 security issues.
I really liked The Vue class component pattern. Localized styles, logic, and markup, coherent state management built-in.
The tooling got more bloated in time, but it was still a breeze to work with.
I'm now trying to catch up with React again as industry tends to dictate—so far so good, but I liked the "pure"/Vue-flavoured HTML markup approach of Vue over JSX. It seemed to have all the benefits of JSX a la close-coupling in class components, but saves the wonky half-flavour of markup/logic—especially when it comes to working in TypeScript.
That said, maybe my tune will change after I spend more time in the React ecosystem again—especially trying to make more use of server-side rendering.
What I don‘t like:
- jsx support is second class
- composition is wonky (better in3?)
- typescript is wonky (better in 3?)
- automatic reactivity is less predictable than the explicitness in React
- automatic reactivity on complex data structures is wonky
- no more than one component per file
- the "official" router is config based. I like the component composition of react-router
What I like
- way easier to learn for any previous web developer
- vuex. I think global state libs are overused but if you need one, it‘s nice and it‘s great that you don‘t have to glue it to the framework yourself
- significantly smaller and faster
- can realistically work without a bundler directly in any html page
> I think I do prefer working with JSX versus using html templates.
I thought I'd prefer JSX too, but I've come to much prefer Vue templates. Turns out that, while it's nice to have the "direct" control, I prefer seeing a full context that the template gives you, rather than having a lot of broken up parts, like JSX.
That said, it is slightly easier to refactor stuff in JSX.
Overall I just have a strong aesthetic preference for Vue too. It feels clean and I have a higher appreciation for the quality of my work when I use it. React apps I work on always feel like they’re not quite “there”, there’s so many different parts that it never feels fully coherent to me.
The worst part so far has been mostly related to the ecosystem. I find Next superior and better maintained than Nuxt, and the 2/3 transition situation looks like a really bad thing to me (sadly reminds me of the python 2/3 situation).
Also, it might have been caused by the specific teams I've been part of, but with react I always find there is a huge tendency to overengineer everything and make things a lot more complicated they should be in the name of purism or whatever reason. I consider myself as a more pragmatic person and Vue fits me a lot better overall.
It’s nowhere close to the python version debacle that I first came across back in 2012, which was already years old. Vue v3 is very new if not bleeding edge. And there are polyfills for new v3 features like the Composition API[0].
I'm impressed. Great work Vue team. I'm normally hesitant to adopt a new version of a library when learning and expected to get bitten by a few more things but so far seems mature, stable, and well done.
Edit: That said, I'm still personally not in love with the .vue file structure of mixing languages, but I get it.
The one page vue file made a lot of sense to me off the bat, sort of implying that the component is a singular "encapsulated" entity, at least thats my own mental model. Turns out it was completely wrong but it worked.
The style requires you a `scoped` to opt in isolation with element created by other component.
Which always make me wonder about why such default is selected.
The <script> and <style> tag default to Javascript and CSS languages in HTML but Vue's compiler allows you to use other languages like Typescript or Sass automatically (assuming you have the dependencies installed). You can also similarly have the code inline between the tags or point to a separate external file with the src="..." attribute.
This means instead of doing `dispatch("action")` you just call `action()`.
When using Typescript this is a godsend, as the action functions keep all of their type information.
- full typing
- real life functions
- vue dev plugin support in store section
- mutations don't exist as separate idea
- also has api, so i wrote little plugin for state synchronization with local storage.
*Typography fix
Definitely going to use it for my future project.
I read the doc and it makes sense but once in my project, I fail to see why I would use it, and yes I use vuex.
I probably need to make a Vue3 project from scratch without vuex to get it.
https://github.com/kiaking/rfcs/blob/vuex-5/active-rfcs/0000...
The effect was just brutally hideous, but it worked.
Makes one wonder if all this sophisticated tooling we're using currently is actually worth it.
> who cares?
Some people want their whole website to work for all visitors, so they care about bugs. Some people want their website to stay online and not to be misused by spammers and co, even for non-commercial sites, so they care about security. Some people want their website to evolve for years, so they care about maintainability.
Shipping junk code is delivering... Then a few years later, the owner wants to fix the bugs and add features, and they learn that no one wants to do it unless it's a full rewrite of the legacy code. They have to pay twice for the same features.
I may be exaggerating but, as always, engineering is all about trade-offs.
Edit: Actually it seems that a solution to .value's everywhere has been postponed and is currently discussed in https://github.com/vuejs/rfcs/discussions/369. The current iteration still requires unwrapping inside the script tag. The docs doesn't seem to make this clear since the examples are too simple...
There are a bunch of breaking changes to Vue 3 that will require code changes, and whilst the vue compat package is meant to alleviate some of that it was only released as of v3.1 and still does not handle all the breaking changes. Some of these breaking changes also seem like they could have been been a good addition and not a full breaking change. Consider the v-model changes, why change the underlying events? You could have it work both the old and new way and log a deprecation warning for the old way. Give engineers more time to fix the code as they see these issues with out breaking.
Probably the biggest pain point I have hit with moving to v3 is the state of vue-test-utils, it is still in RC. Honestly I would have loved to seen this released in lock step with Vue, I mean it really should if it is how you are meant to unit test your components.
That being said obviously a lot of my pain is coming from v2 to v3 I imagine being green field the experience would be fantastic. I still really love using Vue just the upgrade has left a bit of a sour taste in my mouth.
(edit formatting)
I remember seeing a FR for it in GitHub for it. But can't remember where they landed on it.
I am sure emacs can be made to do this, but I wonder if vscode has a plugin for it...
But I'll say this. Thank goodness I don't consider myself a frontend dev.
The selling point of Vue was that it's supposed to be less of a learning curve compared to React. It's "closer" to regular HTML and JS. Except it's not really. You still should not mutate component "properties". If you ask anyone any question about anything, the answer is "use Vuex"- even if it has nothing to do with what you're trying to accomplish. There is definitely a learning curve around its reactivity model (this has supposedly improved with version 3). And I found some stuff just awkward, e.g., Vue components have lifecycle hooks that "support" async/Promises, but the lifecycle doesn't await the Promises, so I had some initialization that had race conditions and I didn't realize why/how.
I don't know if that's good or not, honestly. I just know that Vue2 has certainly not made me enjoy frontend work any more than I did before (which wasn't much).
I used Vue 2 as my main framework for some years, and still maintain a couple of projects with it.
I'm now focused on Svelte. The performance is better, the bundle sizes are much smaller, and most importantly you write a fraction of the code to achieve the same thing.
Svelte also has a reactive primitive (they call them stores) which allows you to model pretty much anything with reactivity similar to what you'd do with MobX but with a fraction of the cost. I believe Vue 3 also has this now but uses Proxy which is not supported in older browsers.
I did try it and even though it's advertised as somewhat backward compatible it did break lots of things, which was totally expected and it's a major release.
Also we couldn't figure out a lot of things, like how can I access the $children like before, why does everything show Object proxy in console, etc. Posting on SO and forums also didn't yeild much help since everyone is still discovering it too I guess.
So in the end we decided why fix something which ain't broken for now. Vue 2 still kicks ass performance wise and is really easy to use.
The browser underlying stack is always going to be there regardless of what is fashionable to wrap around it.
To use your phrasing, React and JSX are always going to be there regardless of what is fashionable for them to be wrapped around.
Cordova => React Native => Flutter => who knows
It helped me a lot.
I believe `npm install vue` even still gives you Vue 2.
In the first half of 2021, I dove deep into Vue, Vuex, Nuxt.js (basically Next.js), Gridsome (basically Gatsby.js), and even coded a startup idea using Vue + Electron + FFmpeg[0] before moving to React. Three main reasons for this switch:
- Community Support: React has better support for lots of JS libraries. For example, I made a markdown editor which required the use of CodeMirror and the React NPM library for that was updated 1 year ago while the Vue library was updated 3 years ago. There's a lot of international support for Vue and some of the NPM libraries (like the CodeMirror one) are partially (or fully) documented in Chinese so this is a drawback as well.
- Typescript: Vue 3 is built from the bottom up with TypeScript but it was only released in September 2020. Most of the community thinks Vue 3 is better than Vue 2 in TS support, but still not as good as React. Additionally, since TS support has only recently been offered, libraries (like Nuxt.js) have not been updated with TS support.
- Job Market: React is the clear winner whether you are building a startup (and looking to hire developers), or want to join a company (at least in the US).
I think Vue has lots of potential to improve in all three areas but it's just not there right now. You can see my full thoughts on YouTube[1].
[0] https://www.reddit.com/r/webdev/comments/ohbl6i/i_made_a_des...
I've also never met a library that couldn't be integrated into Vue easily, whether through an official solution, a 3rd-party library or analogue, or simply integrating it yourself. I will give you that there are certainly more libraries catering to React specifically.
React has much better typescript support, as it type checks all props, even complex objects.
If you are also using GraphQL, I recommend taking a look at the new composition API support in Vue Apollo [1] as well. This post [2] summarizes how this integration looks like in practice for a typescript project.
[1] https://v4.apollo.vuejs.org/guide-composable/
[2] https://lorefnon.me/2021/08/08/Vue-composition-api-and-type-...
A lot better, imho.
I've worked on projects that use Vue 2 HTML templates + TypeScript before and a big chunk of the bugs are clustered around where TypeScript is interacting with the HTML templates.
Are there any problems with Vue + JSX + TypeScript when you want to use Vue UI component libraries that use Vue + HTML? Will you be giving up any static type checking here?
<span :style="{ color }"> Color is: {{ color }}</span>
Simpler than this new syntax, for this particular example.
I can't stand Vue (but haven't tried newer versions).
The reason is that Vue is miserable to debug in the browser. It is really clever to use proxies for values but then you have to make an extra click to see the actual value and it really slows you down. Recreating the state of the app inside your head can't be done quickly because you have to manually evaluate everything you need to do that.
Vue also uses it's own DSL that generates a bunch of code under the hood, which confuses the browser.
These things could have changed in recent versions of Vue but I had such a poor experience that I would never go back.
I had to respond to this comment because the reason you have fewer libraries for Svelte is that Svelte is just JavaScript. It is trivial to use any JavaScript library because it requires no integration wrapper to convert that library to Svelte. Just use it as you would without Svelte. It's a much better experience than Vue or React can ever give you.
With https://chrome.google.com/webstore/detail/vuejs-devtools/nhd... ???
Does this work on Firefox, I recently switched to that?
The React extension was/is great, I assume this one for Vue is as well. But, it wasn't there when I was doing Vue and the out of box experience of Vue was not good because of it.
I wish people would stop saying things like "is just JavaScript". All these frameworks do fancy things with JavaScript, and they're all just as much JavaScript as each other. Also they _all_ use DSLs; Vue, react, and svelte.
I would argue very much against that: Svelte looks like Javascript, but behaves completely different. I don't think it's a bad thing, and quite enjoy it, but I don't think it's valid to call a language that happens to be valid JS syntactically actually JS.
> It is trivial to use any JavaScript library because it requires no integration wrapper to convert that library to Svelte. Just use it as you would without Svelte.
What do you mean by this? Of course you can use a standard JS library with any other framework! What makes Svelte different here?
No. This is complete and absolute FUD that you are spouting. Svelte adds a thin feature or two on top of vanilla Javascript. The rest is just JS exactly like you know it.
You can see what Svelte creates inside the tutorial. It's very simple JavaScript.
With React or Vue, you are pulling a bunch of stuff written in a DSL into their massive runtime. Try keeping all that complexity for that runtime in your head.
All JS frameworks are just Javascript. What else would they be? The templates however are all specific DSLs, whether it's JSX, HTML with directives, or Svelte's own syntax. In the end these template just get compiled into a JS render function that takes in data and returns an HTML structure.
JSX is not JavaScript. React builds an entire system hidden from you that isn't the way JavaScript runs.
What abstraction are you thinking in? With Svelte I'm thinking in JavaScript. With Vue and React I'm thinking in hooks-land or whatever, and trying to understand a completely different virtual machine. There are some really brilliant ideas they have come up with, but the whole cloth experience isn't for me.
Vue is worse. Create an item inside the data attribute. Somehow that becomes available to computed functions. Somehow you can have that data attribute rely on parent attributes. None of that is the way JavaScript works without Vue on top. I'm so glad I don't have to remember those rules anymore.
You are correct they just compile into render functions. But the one Svelte produces is readable and the ones produced by Vue and React are a lot less so.
Anyway there is no other abstraction. Hooks and composition APIs aren't magic, they're functions that you can write yourself. It's basic property change notifications but wrapped up in various levels of automation. Vue's object API can definitely seem messy but the new composition APIs in Vue 3 is standard JS syntax. Maybe it would be helpful to see the code yourself: https://github.com/vuejs/vue-next/tree/master/packages/react...
(This is a complaint about React, but...) I really find hooks/effects to be pretty magical. Keeping track of how many times a hook/effect runs is really difficult for me. It looks so simple at first, but there is a lot going under the hood to figure out how often they run.
Vue can also use the html as the component template like angulajs 1 used to allow. This makes it great for progressive enhancement and plays nice with server side based template frameworks.
Bottom line, vue scales up, but also scales down. You don't need to go full spa, you can hack a quick demo or make a one file tutorial and it's a bliss.
Also, maybe I missed it, but I don't think svelte has the concept of cached properties.
This is actually the biggest selling point IMO. I used Svelte instead of Vue purely for speed, but the benchmarks suggest Vue has made real progress here. Though, I'm not sure that in real applications a virtual DOM solution could ever be quicker than compiled code to update state. But in terms of developer UX, I think Vue has the easiest entry point, and it seems to have decent performance to boot
I know about real world projects that use Vue as a progressive enhancement on an existing PHP site. A weather card is, for example, being managed by Vue with it's reactivity engine.
Developers, in general, despise XML. However, React which is the market leader and generally well-liked is littered with JSX/XML.
React developers aren't trying to make their documents into databases.
React developers aren't trying to turn their little blocks of markup into an ontology.
Everything in Vue is more complicated. They went with this whole template language which is just a mess and has extremely poor tooling support. Everything is more complicated and harder to reason about. You literally need(ed) several files to write a single component which could be a couple of lines of JSX in React. Since the tooling support is so poor and it is so over-engineered, it is extremely difficult and bothersome to get it fully typed.
I'm just really glad that I don't have to work with it on a daily basis.
Can you give a few examples of things that bug you?
At its core, however, everything just 'clicked', the templating works beautifully, and single-file-components are superb. I'll write React and Ember when necessary, but coming back to Vue is always a welcome relief.
I've lost count of the number of times I decided to start off writing what felt 'right' intuitively, and found things just worked first time. In that sense at least, there are echoes of Rails for me.
Also with Vue, you have community driven direction, rather than FB. This is a big positive for me.
That was one of the top selling features for me as well. Not to disparage the large amount of work and thought and care that's gone into work on React, but when the tooling lies primarily in the hands of one company I get those old-fashioned Oracle vibes.
And that whole extra language just for templates is annoying, and unnecessary. I don't want a v-else-if="level ==== 6", because I'm going to make typos, and I want the ability to refactor code in the future without painstakingly reviewing every string in the codebase.
How good is the jsx integration in practice? It's there, but the vue docs recommend against it, without going into details of the motivation.
I agree that ternaries aren't the prettiest of language idioms, but if clearly formatted (e.g. eslint defaults are fine), I think it's mostly a question of getting used to it. I mean, the tricky but also common && and || are almost certainly worse for this, I suppose?
I've used Vue on several other projects and have enjoyed using it every time. I like that parts of the Vue framework are optional. Don't want the router or state management? Don't use it. The codebase is well organized, the output files are small and the app is performant.
I don't like all the dev dependencies you need to get going, but I have that same complaint about most other modern front-end frameworks.