【问题标题】:Access Nuxt.js context in Vue plugin在 Vue 插件中访问 Nuxt.js 上下文
【发布时间】:2019-08-25 22:05:37
【问题描述】:

我正在使用 Nuxt.js,并且安装了两个插件。 我需要从 validate.js 中的 lang.js 访问 VueI18n 实例

有人知道怎么做吗?


lang.js

Vue.use(VueI18n)

export default ({ app }) => {
  app.i18n = new VueI18n({
    locale: 'en',
    messages
  })
}

validate.js

Vue.use(VeeValidate, {
  i18nRootKey: 'validations',
  i18n,  // access the VueI18n instance from plugin above
  dictionary: {
    en: validationMessages
  }
})

export default ({ app }) => {
  // This way I could get the instance but how to add it to the plugin?
  console.log(app.i18n)
}

【问题讨论】:

    标签: javascript vue.js nuxt.js


    【解决方案1】:

    只需将你的 vue.use 移到 export default 中

    export default ({ app }) => {
    
    Vue.use(VeeValidate, {
      i18nRootKey: 'validations',
      i18n: app.i18n,  // access the VueI18n instance from plugin above
      dictionary: {
        en: validationMessages
      }
    })
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-25
      • 2018-11-06
      • 2020-04-17
      • 2021-07-24
      • 1970-01-01
      • 2020-11-29
      • 2020-02-08
      • 2019-08-19
      • 1970-01-01
      相关资源
      最近更新 更多