Hacker News new | ask | show | jobs
by TekMol 2288 days ago
Can someone give a quick code example for the follwing?

    The framework allows UI elements
    to be defined in a declarative way
How can you use Vue so that what you do is more declarative then when using a template engine like handlebars?
1 comments

I believe the templating is what's declarative, here. For instance, in Vue you can insert logic such as for loops, conditionals, event listeners, two-way data binding and so on right in the template with directives (HTML attributes).

    <Todo v-for="(todo, index) in Todos" :key="index"/>
Instead of an imperative JavaScript for loop.
It is the same with handlebars. You put your todo element between {{#.}} and {{/.}} which means "do this for all elements" and then pass only the "Todos" array to the template. No loop in Javascript either.
How in seven hells is moving imperative loop constructs from Javascript to HTML supposed to be "declarative"?!

If anything, it's the opposite - you're now polluting HTML with imperative programming features where there previously were none.