[Vuejs]-How to properly add a global property to work in a component template? (Vue 3, vite, typescript, composition api)

0👍

This solution worked after I rebuilt the app

declare module '@vue/runtime-core' {
    interface ComponentCustomProperties {
        $t(key: string): string
    }
}

0👍

You need to reference the ‘$t’ variable also in your main.ts. This is the only solution I’ve found. You can also try to define your property like so:

Object.defineProperty(app.config.globalProperties, '$t', {
        /* your definitions here */
      })

Leave a comment