vue多语言解决方案

57 阅读1分钟

方案1

vue-multilanguage

链接

npm : www.npmjs.com/package/vue…

方案2

vue-translation

链接

  <translation :lang="locale">
    <p>Hello World!</p>
  </translation>
</template>

<script>
import { Translation } from 'vue-translation'

export default {
  components: {
    Translation 
  },
  data() {
    return {
      locale: 'en' 
    }
  }
}  
</script>

在main.js中使用

import vueTranslation from 'vue-translation'

Vue.use(vueTranslation)

// 注册语言包
vueTranslation.addMessages({
  en: { /* ... */ },
  zh: { /* ... */ } 
})

new Vue({
  // ...
})