DEV Community

Discussion on: Why you should be using Vue's new Composition API

Collapse
 
pawelmiczka profile image
Paweł Miczka • Edited

I started using Composition API with TypeScript last year and damn - that was great experience. Not only because code looks "cooler" and cleaner but also with fact that you can much easier split your code into single "plugins".

With this you can move things like onMounted etc. to separated files and implement those without any problem to any component you want.

There is one great thing that was implemented in 3.2 - <script setup> which transforms your code from this:

<script>
// imports here

export default defineComponent({
   setup() {
      const name = ref('')

      return { name }
   }
})

</script>
Enter fullscreen mode Exit fullscreen mode

to this:

<script setup>
// imports here

const name = ref('')

</script>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
pawelmiczka profile image
Paweł Miczka

You don't need to use Composition API, sure but I think you will :D