Vue 3: Is getCurrentInstance() deprecated?

getCurrentInstance() was removed from the Vue 3 docs because it’s an internal API: Because the instance is an internal instance that exposes non-public APIs. Anything you use from that instance can technically break between any release types, since they are not subject to semver constraints. getCurrentInstance() was originally documented in 4-Oct-2020, but that was later … Read more

Vue 3 Vite – dynamic image src

Update 2022: Vite 3.0.9 + Vue 3.2.38 Solutions for dynamic src binding: 1. With static URL <script setup> import imageUrl from ‘@/assets/images/logo.svg’ // => or relative path </script> <template> <img :src=”imageUrl” alt=”img” /> </template> 2. With dynamic URL & relative path <script setup> const imageUrl = new URL(`./dir/${name}.png`, import.meta.url).href </script> <template> <img :src=”imageUrl” alt=”img” /> … Read more

Add global variable in Vue.js 3

The most direct replacement is app.config.globalProperties. See: https://vuejs.org/api/application.html#app-config-globalproperties So: Vue.prototype.$myGlobalVariable = globalVariable becomes: const app = createApp(RootComponent) app.config.globalProperties.$myGlobalVariable = globalVariable This is scoped to a particular application rather than being global as it was with Vue.prototype. This is by design, all ‘global’ configuration options are now scoped to an application. The relevant RFC is here: … Read more

Vue 3 reactivity not triggered from inside a class instance

As another answer explains, reactive creates proxy object to enable the reactivity. this in constructor refers to original MyClass instance and not a proxy, so it cannot cannot be reactive. This indicates the probem in the code. reactive takes into account synchronous operations that occur in MyClass constructor. It’s an antipattern to perform asynchronous side … Read more

ref vs reactive in Vue 3?

Key Points reactive() only takes objects, NOT JS primitives (String, Boolean, Number, BigInt, Symbol, null, undefined) ref() is calling reactive() behind the scenes Since reactive() works for objects and ref() calls reactive(), objects work for both BUT, ref() has a .value property for reassigning, reactive() does not have this and therefore CANNOT be reassigned Use … Read more