Skip to content

Commit 8b98d0b

Browse files
committed
fix: missing support for Vue3 vapor mode in the options API
1 parent 100c669 commit 8b98d0b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/vue-i18n-core/src/mixins.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { createEmitter } from '@intlify/shared'
2-
import { getCurrentInstance } from 'vue'
32
import { addTimelineEvent } from './devtools'
43
import { createI18nError, I18nErrorCodes } from './errors'
54
import { createVueI18n } from './legacy'
65
import { SetPluralRulesSymbol } from './symbols'
7-
import { adjustI18nResources, getLocaleMessages } from './utils'
6+
import {
7+
adjustI18nResources,
8+
getCurrentInstance,
9+
getLocaleMessages
10+
} from './utils'
811

912
import type { Locale, LocaleMessageValue } from '@intlify/core'
1013
import type { Path } from '@intlify/core-base'
@@ -118,11 +121,14 @@ export function defineMixin(
118121
if (
119122
(__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) &&
120123
!__NODE_JS__ &&
121-
this.$el &&
122124
this.$i18n
123125
) {
126+
const instance = getCurrentInstance()
127+
if (!instance) {
128+
return
129+
}
124130
const _vueI18n = this.$i18n as unknown as VueI18nInternal
125-
this.$el.__VUE_I18N__ = _vueI18n.__composer
131+
instance.__VUE_I18N__ = _vueI18n.__composer
126132
const emitter: VueDevToolsEmitter = (this.__v_emitter =
127133
createEmitter<VueDevToolsEmitterEvents>())
128134
_vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter)
@@ -143,16 +149,15 @@ export function defineMixin(
143149
if (
144150
(__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) &&
145151
!__NODE_JS__ &&
146-
this.$el &&
147-
this.$el.__VUE_I18N__
152+
instance.__VUE_I18N__
148153
) {
149154
if (this.__v_emitter) {
150155
this.__v_emitter.off('*', addTimelineEvent)
151156
delete this.__v_emitter
152157
}
153158
if (this.$i18n) {
154159
_vueI18n.__disableEmitter && _vueI18n.__disableEmitter()
155-
delete this.$el.__VUE_I18N__
160+
delete instance.__VUE_I18N__
156161
}
157162
}
158163

0 commit comments

Comments
 (0)