setup-script is the cool feature of vue but...

setup-script is the cool feature of vue but...

script setup is the cool feature that Vue team introduced. But in some cases, normal script is the better choice.

<script setup> block is compiled into the setup() function for the component.

Why?

Use the options API

Not everything has an equivalent in the composition API, like inheritAttrs.

Run setup code one time

Because setup() is run for every component, if you have code that should only be executed once you can’t include it in <script setup>.

You can put it inside of the regular <script> block though.

Named exports

Sometimes it’s nice to be able to export multiple things from one file, but you can only do that with the regular <script> block.


© 2022. All rights reserved.