feat(floatingBubble): 添加国际化支持

- 在 floating.js 中集成 vue-i18n
- 从 nuxt/app 导入 useNuxtApp 替代 useI18n
- 更新 index.vue 中的国际化使用方式
This commit is contained in:
xingyy 2025-02-27 09:23:01 +08:00
parent d9d52ab7cb
commit df597c0328
2 changed files with 21 additions and 2 deletions

View File

@ -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)

View File

@ -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: {