4 ms·
Have you seen Vue's single file components? It's a (single file), which would look something like (idk how to format code on h/n lol): <template> <ul>
by ElatedOwl 9y ago
Have you seen Vue's single file components?
It's a (single file), which would look something like (idk how to format code on h/n lol):
<template>
<ul>
<li v-for="message in messages">{{ message }}</li>
</ul>
</template>
<script>
export default {
data () {
return {
messages: ['hello', 'world']
}
}
}
</script>
I realize this is a completely trivial example, but is this what you're getting at? Everything related to that component is in a single place. The template itself handles any UI specific logic: conditionally showing an element, looping, binding an event.
Any real logic is going to be handled from the component itself.
That said, Vue actually supports using a render function as opposed to using a template. You can even use JSX if you want (though I certainly wouldn't consider JSX a first class citizen in Vue).
- ng12 9y agoBut do you see the inter-dependencies between the script and the template? The template is assuming that it's provided a variable named messages and that it's an array of ready-to-display strings. And this information is stringly typed -- will your editor complain if you fail to define messages? Can I use Typescript to ensure that each message is what I expect? Sure, it's easy enough for simple examples but I've seen it fall apart quickly for large projects with multiple developers.
- true_religion 9y agoI'm not seeing the issue here. This kind of system is extremely common on the backend---Python's Django and Ruby on Rails, to name a few frameworks follow the practice of templates being given data and simply acting upon it. Since these are dynamically typed languages, there's no IDE typing support in the template. There's just testing. As someone who uses Django regularly, I can say there's a huge swatch of territory between "small examples" and "large projects". That territory can easily cover teams of 19, and multimillion dollar projects.
- ng12 9y agoRight, it's a common technology and it's always been a pain. With React everything is well-defined and typesafe (either through PropTypes, Typescript, or Flow) and the IDE support is fantastic. That's my whole contention -- Vue is just a better iteration of the same old painful experience. React actually solves the problems I have.