4 ms·
Preferred syntax should be enough, but here's a couple more differences: - Vue has a set of core libraries (Vuex, vue-router, etc) maintained by the same org.
by nickdandakis 7y ago
Preferred syntax should be enough, but here's a couple more differences:
- Vue has a set of core libraries (Vuex, vue-router, etc) maintained by the same org.
- Single file components with scoped styling out of the box.
- Vue integration as a standalone runtime is a little easier than React (unsure about this one).
You can read more about the differences here:
https://vuejs.org/v2/guide/comparison.html#React https://vuejs.org/v2/guide/comparison.html#React
I couldn't find any official comparison documentation from the React docs, though.
- ng12 7y ago> Single file components Honestly I think this is a step backwards. How many components my "component" is built out of should be an implementation detail.
- zamalek 7y agoYou're misinterpreting what an SFC is, it's just something like the following: <template> <!-- A mustache-like template --> </template> <script> // JS, TS, or whatever </script> <style scoped> /* CSS, LESS, SCSS or whatever */ </style> That components may use other components itself, no part of SFCs disallow that.
- ng12 7y agoThat's not what I'm saying. What if I have a child component I don't want to put in a separate file? What if I want a child component defined as a closure inside my parent component? What if I want one file that exports many components? React makes no judgements here -- it's completely up to me to decide what's best for my application.
- cooperadymas 7y agoI don't think anything would stop you from creating multiple components in a file using 'Vue.Component' and a template string. I've never remotely wanted anything similar to this in Vue, but I have seen what you're talking about used in React, mostly for component wrappers to encapsulate logic. It's not something I like using or seeing but that could easily be swayed by my preference for Vue. See how it's done in the guide. It wouldn't be as natural as react allows but should suffice for tiny, contained sub components. https://vuejs.org/v2/guide/index.html#Composing-with-Components https://vuejs.org/v2/guide/index.html#Composing-with-Compone...
- ng12 7y ago> 'Vue.Component' and a template string. But the template string is just a string, right? Can you get the same IDE integration while avoiding SFCs?
- cooperadymas 7y agoAt that point it should probably be its own SFC. But You can also override the render function, and even use JSX. https://vuejs.org/v2/guide/render-function.html#JSX https://vuejs.org/v2/guide/render-function.html#JSX
- adamwathan 7y ago> I've never remotely wanted anything similar to this in Vue, This was true of me as well until actually playing more with React. In practice, being able to very quickly extract a child component by just copying a chunk of code to a different spot in the same file is a very nice workflow benefit I now sorely miss when using Vue. In Vue my components tend to be larger and more complex than they are in React because I feel like some small extraction I want to make doesn't "deserve" it's own dedicated file, whereas in React I just quickly make a new function that returns some JSX and I'm done.
- zamalek 7y agoYou don't have to use SFCs (I don't in Vue 2 or Vue 3). However, you would be able to nest components in an SFC so long as you don't expect the <template> tag to work in the interior components (I can't imagine how that would even look and work). The only thing that SFCs do is create a render function for you (as well as some CSS scoping magic). You can do that all yourself and that is all documented and supported behavior. You have completely the wrong idea here and, honestly, this is all in the documentation. > React makes no judgements here Vue typically has fewer opinions than React (and FAR less than Angular) in my experience.
- ng12 7y agoI'm explaining why I don't like SFCs because the above poster referenced them as a "pro" for Vue over React. Whether or not you _have_ to use them in Vue is immaterial.
- reubens 7y agoYou can do this within Vue if you like - you just increment the complexity of your exisiting component, rather than creating a new child
- cooperadymas 7y agoIt largely is an implementation detail. The official guide starts you off without them. You ostensibly could develop an entire application without touching SFC or using the vue cli. But they're such a well implemented pattern that you'll find almost no one in the wild avoiding them, which is pretty telling.
- ng12 7y agoCorrect me if I'm wrong but I imagine that's more for the tooling (e.g. syntax highlighting for my template and styles) than an actual preference for SFCs.
- cooperadymas 7y agoShrug. Maybe? I think Vue is popular enough that if people actually disliked SFCs once they started using Vue they you would see blog posts about how to avoid them, complaining that's why they're leaving Vue, or tooling that makes it easier to bypass them. I don't really see this so my assumption is devs generally like them once they start using them. I could certainly be proved wrong.
- jplayer01 7y agoA bit tangential - I've been messing around with vuejs and Django recently (I'm not a web developer in the slightest) and I haven't found a decent way to get webpack integrated. So I can't use SFC or cli and I wonder how people do this in the real world. Do people even use vue with Django?
- thefreeman 7y agoThey are generally deployed separately. Django is used to build a rest API and webpack / Vue are deployed on their own to consume the API. You can put something like nginx in front to route API requests to Django and everything else to an s3 bucket for your single page app.
- jplayer01 7y ago
- jimktrains2 7y agoIt isn't? You don't have to define them in a single file. I prefer having the template, styles, and code together, but it isn't required.
- Rapzid 7y agoWouldn't mind some other opinions on this but having used Mobx a lot in the past and starting to look at Vuex for current employer it's not looking enticing in comparison.. Mobx will work with Vuejs and I'm reading about a lot of people who have switched from vuex and been very happy. Considering just jumping in with Mobx and the bindings.. My and many others dev environments lean heavily on Vetur and it.. Is plagued with various issues in various releases. JSX/TSX JustWork™ while SPCs are okay sometimes but other times are found wanting..