by therealmarv · 7y ago · 0 comments
Look at this beauty for comparison: https://vuejs.org/v2/guide/single-file-components.html
https://vue-loader.vuejs.org/guide/scoped-css.html#scoped-cs...
Inspect the result here: https://codesandbox.io/s/3v0pjzoy7q
Where is template getting assigned to the code inside the script tag?
Does OtherComponent somehow mysteriously map to other-component? How does one pass arguments to it? Is a .vue file actually HTML or is it parsed somehow to be HTML?
The thing I like about React is the explicitness of it. This is a source code file that exports component X. Component X uses style Y as defined above because it's explicitly passed in as a prop, etc etc.
What language are you talking about? React is Javascript
> Look at this beauty for comparison
Meanwhile Vue is neither HTML [1], nor strictly speaking CSS [1], and has a very wierd concept of how objects work in JS.
[1] It's a templating system with its own rules and mini-DSLs that ends up being compiled into JS.
Vue Templates are a very thin DSL on top of HTML. It's just markup.
Once you understand that, everything falls into place.
What is so weird about it? I personally find Vue vastly more approachable than React is, especially once you have to start writing all the plumbing to get all the libraries you need to go along with it to write a real world app.
> ] It's a templating system with its own rules and mini-DSLs that ends up being compiled into JS.
Vue has the option to use Webpack to compile html compliant templates to JS functions just like JSX (which BTW is not JavaScript and not HTML compliant and is also a separate concept that needs to be learned as well.)
CSS is just another add-on through Webpack when using Single File Components. Nothing really ground breaking here except for the fact that it creates a nice separation of concerns. This is especially true on teams with junior devs or designers. Or with a team that works on a site with mixed MPA and SPA features.
I go a bit in depth here: https://news.ycombinator.com/item?id=17471199
> Vue has the option to use Webpack to compile html compliant templates to JS functions just like JSX
Vue's templates are not HTML-compliant. They are just that: templates. That get compiled to JS anyway.
> JSX (which BTW is not JavaScript and not HTML compliant and is also a separate concept that needs to be learned as well.)
JSX is a very thin DSL on top of Javascript. It's just function calls: https://reactjs.org/docs/react-without-jsx.html
Once you understand that, everything falls into place.
> CSS is just another add-on through Webpack when using Single File Components.
It's not a webpack add-on. It's a part of Vue's templating engine that is essentially CSS-in-JS, they just give you a template to work in.
It's regular CSS in the templates and regular CSS in the frontend. There's no JS involved anywhere, unless you count the tooling, but we already use JS tools for CSS processing (PostCSS).
Scoped CSS is an old HTML5 feature that was dropped in favor of style encapsulation using Shadow DOM/Web Components.
It means you can't abuse JavaScript everywhere, creating totally unreadable render function, nest array mapping in Ternary operator and reduce it to what the hell no one can read and destroy all the readabilities.
For me, for you, for everyone, if you using that syntax, then it is simply readable just like html.
Less powerful, but the management definitly worth more.
I've read this before. Vue is a framework. It also has a templating system that is not JavaScript, it's valid HTML with attributes that tell Vue how to bind to it. It's really not that difficult.
> Vue's templates are not HTML-compliant. They are just that: templates. That get compiled to JS anyway.
Sorry, but you're wrong here. They are valid HTML.
https://vuejs.org/v2/guide/syntax.html
"Vue.js uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the underlying Vue instance’s data. All Vue.js templates are valid HTML that can be parsed by spec-compliant browsers and HTML parsers."
> JSX is a very thin DSL on top of Javascript. It's just function calls: https://reactjs.org/docs/react-without-jsx.html
IMHO only the simplest of components featuring JSX that don't read like a spaghetti PHP coding nightmare to me. For the small number of times you actually need the full power of JavaScript you could also use JSX in Vue with a render function if necessary. I personally prefer to keep my templates and logic separate when possible.
> It's not a webpack add-on. It's a part of Vue's templating engine that is essentially CSS-in-JS, they just give you a template to work in.
No, it's not part of the template engine, it's part of vue-loader which is used by Webpack to create single file components.
With its own syntax. Which looks like HTML but isn't.
Add in Tailwind utility classes and you've got a great design system that can be built on the fly with consistent standards.