const { createI18n, useI18n } = VueI18n; // 通过选项创建 VueI18n 实例 const i18n = createI18n({ locale: localStorage.getItem('changjiang-park-lang') || 'zh-cn', messages, fallbackLocale: 'zh-cn', legacy: false, }) const sharedMixin = { data() { return { languageList: [ { id: 1, name_loc: '简体中文', symbol: 'zh-cn' }, { id: 2, name_loc: 'English', symbol: 'en-us' }, // { id: 3, name_loc: 'ar', symbol: 'ar' }, ], currentLang: 'zh-cn', i18n: i18n.global, // 引入i18n实例 } }, // 生命周期 - 创建完成(可以访问当前this实例) mounted() { this.currentLang = this.i18n.locale || 'zh-cn'; }, // 创建生命周期 created() { }, // 方法 methods: { ///// 切换语言 ///// changeLanguage(newLang) { this.i18n.locale = newLang; // this.i18n.currentLocale = newLang; this.currentLocale = newLang; localStorage.setItem('changjiang-park-lang', newLang); window.location.reload(); }, } }