iT邦幫忙

1

Vue-i18n 在 .vue 檔裡面的話該怎麼做?

import Testvue from 'testvue.vue';
import i18n from 'lang';
import en from 'en/lang.json'; // 存放英文翻譯
import cn from '/cn/lang.json'; // 存放中文翻譯

// Define component
const Component1 = {
template: Testvue,
i18n: { // i18n option
en : en,
cn : cn
}
};

new Vue({
i18n,
components: {
Component1
}
}).$mount('#app')

怎麼在 .vue 使用 i18n
testvue.vue 裡面有template 與 javascript 兩塊

執行後出現兩個錯誤
racing-car-message.js:10300 Uncaught TypeError: Cannot read property 'componentInstance' of nul
Cannot read property componentInstance of null

後來解決了.

.vue 裡面要用 i18n 加 this 就可以了
this.$t('hello')

mengke.me iT邦新手 5 級 ‧ 2021-12-15 10:23:37 檢舉
推荐使用i18n https://www.npmjs.com/package/i18n,你用的这个lang没有用过
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答