VueJs and vue-i18n error

im using the webpack CLI template.

Then I install https://kazupon.imtqy.com/vue-i18n/ with the installation of npm --save vue-i18n

In my main.js, I am importing and setting the locale to "en"

import Vue from 'vue' import VueI18n from 'vue-i18n' import App from './App' import router from './router' Vue.use(VueI18n) Vue.locale('en', {}) new Vue({ el: '.nwt-mm-app', router, template: '<App/>', components: { App } }) 

Exit to the console always says

 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_vue___default.a.locale is not a function at eval (eval at <anonymous> (app.js:802), <anonymous>:16:45) at Object.<anonymous> (app.js:802) at __webpack_require__ (app.js:660) at fn (app.js:84) at Object.<anonymous> (app.js:1176) at __webpack_require__ (app.js:660) at app.js:709 at app.js:712 

Am I a little lost? Hello,

Marcus

+5
source share
2 answers

Well, you can check out another repo for the author.

https://github.com/kazupon/vue-i18n-alpha-repro

In a demo, vue-i18n looks like this:

 import Vue from 'vue' import App from './App' import VueI18n from 'vue-i18n' import router from './router' Vue.use(VueI18n) const i18n = new VueI18n({ locale: 'ja', messages: { ja: { hello: 'こんにちは' }, en: { hello: 'hello' } } }) Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, i18n, template: '<App/>', components: { App } }) 

And it works.

+3
source
 import Vue from 'vue' import VueI18n from 'vue-i18n' Vue.use(VueI18n) // console.log(navigator.language); let defaultLang = "zh" const i18n = new VueI18n({ locale: defaultLang,//默认语言messages: { zh:{ hello:'你好', footTitle:['现货交易','采购供应','行情资讯','个人中心'] }, en: { hello: 'hello', footTitle:['Spot Trading','Purchase & Supply','Market Information','Personal Center'] }, } }) export default i18n 
-1
source

Source: https://habr.com/ru/post/1264781/


All Articles