diff --git a/app/components/floatingBubble/floating.js b/app/components/floatingBubble/floating.js index 111ffa8..c68d333 100644 --- a/app/components/floatingBubble/floating.js +++ b/app/components/floatingBubble/floating.js @@ -4,6 +4,7 @@ */ import { createApp } from 'vue' import MinWindow from '@/components/floatingBubble/index.vue' +import { createI18n } from 'vue-i18n' // 全局单例状态管理 let minWindowInstance = null // 组件实例引用 @@ -39,6 +40,21 @@ export const showMinWindow1 = (props = {}) => { // 创建Vue应用实例 const app = createApp(MinWindow, props) + + // 获取当前 Nuxt 应用的 i18n 配置 + const nuxtApp = window?.__nuxt + const i18nConfig = nuxtApp?.$i18n?.options || { + legacy: false, + locale: 'en', + messages: {} + } + + // 为独立组件创建 i18n 实例 + const i18n = createI18n(i18nConfig) + + // 安装 i18n + app.use(i18n) + minWindowApp = app minWindowInstance = app.mount(container) diff --git a/app/components/floatingBubble/index.vue b/app/components/floatingBubble/index.vue index c9087e0..ad029ed 100644 --- a/app/components/floatingBubble/index.vue +++ b/app/components/floatingBubble/index.vue @@ -6,9 +6,12 @@ import { watch, onUnmounted } from 'vue' import { hideMinWindow1 } from './floating' -const { t } = useI18n() +// 从 nuxt/app 导入 useNuxtApp +const { $i18n } = useNuxtApp() + +// 替换原来的 useI18n +const t = (key) => $i18n.t(key) -// 组件属性定义 const props = defineProps({ /** 点击气泡时的回调函数 */ onClick: {