Hacker News new | ask | show | jobs
by enraged_camel 3360 days ago
I use single-page components in Vue and write templates like this:

  <template>
      <div>
          <h2>{{ title }}</2>
      </div>
  <template>

  <script>
    export default {
        data() {
            return {
                title: "Hello world"
            }
        }
    }
  </script>
Works well in my opinion. Separates the template into its own section but keeps it inside the same file.
1 comments

In my mind this is strictly inferior to JSX, which would be:

   export default ({title}) => (
      <div>
         <h2>{title}</h2>
      </div>
   )
The only benefit to the template is if you use fancy features (#each, binding, etc) which is worse because now you have two places where the logic happens.