Composables | Vue.js thumbnail
Composables | Vue.js
vuejs.org
<script setup> is the only place where you can call composables after using await. The compiler automatically restores the active instance context for you after the async operation. Remember to clean up side effects in onUnmounted(). For example, if a composable sets up a DOM event listener, it shou
1 Users
0 Comments
5 Highlights
1 Notes

Top Highlights

  • <script setup> is the only place where you can call composables after using await. The compiler automatically restores the active instance context for you after the async operation.
  • Remember to clean up side effects in onUnmounted(). For example, if a composable sets up a DOM event listener, it should remove that listener in onUnmounted() as we have seen in the useMouse() example. It can be a good idea to use a composable that automatically does this for you, like the useEventListener() example.
  • If you prefer to use returned state from composables as object properties, you can wrap the returned object with reactive() so that the refs are unwrapped. For example:
  • The recommended convention is for composables to always return a plain, non-reactive object containing multiple refs.

Domain

Ready to highlight and find good content?

Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.