[Vue3多語系]i18n的this.$t寫法無效
使用vue-i18n編寫多國語言時
vue3中 setup()內無法使用 this.$t('語系代碼’) 這模式
需轉為以下的方式
1 2 3 4 5 | export default { setup(){ const { appContext : { config: { globalProperties } } } = getCurrentInstance() console.log(globalProperties.$t( 'page.title' )) }} |
ps.以上是適用於main.js中已有全局引用i18n的狀況
關鍵字可查 createApp(App).use(i18n).use(router).mount('#app’)