I am declaring $bus in vue prototype to access globaly but getting this error
Property `prototype` does not exist on type vue.
Can some help me how to declare with typescript. Vue version is 3.
I am declaring $bus in vue prototype to access globaly but getting this error
Property `prototype` does not exist on type vue.
Can some help me how to declare with typescript. Vue version is 3.
You would no longer inject it into the Vue prototype. If you want to make it globally accessible in a way that is similar to the prototype method you could use the global properties from the application instance.
const appInstance = createApp(MyVueApp);
appInstance.config.globalProperties.$bus = myBus;
appInstance.mount('#appId');
if you want to access it from a component, for Option-API components, you can access with this.$bus
. For Composition API, you need to get the instance with getCurrentInstance
Vue method, so: getCurrentInstance().appContext.config.globalProperties.$bus
I don't believe there's anything specific to typescript in terms of adding the object to the instance, but you might need to type the $bus
when you're getting it from the globalProerties
object.