Composition API - Creating computed outside of setup or a composition function #9779
-
|
Sorry if that question has been asked already, or if it is even already answered as part of the Vue doc: I tried to search for it without success. In our application I see some export const TypesOfTransports = computed(() => {
BUS: i18n.t('core.bus'),
TRAM: i18n.t('core.tram'),
})It works today, but I am worried that it could cause problems in the future (memory leak, computed that stops updating when a component unmounts...). Because from what I understood, Can someone tell me if it is indeed a bad practice ? Is it documented that vue reactivity functions should only be called inside of components |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
|
Beta Was this translation helpful? Give feedback.
computedis a feature in @vue/reactivity, and you can use it anywhere. If a variable is only needed within a component, it is recommended to use it in the component'ssetup. However, if you have other requirements, you can use it anywhere without causing memory leaks. How you ultimately use it depends on your business needs.