【问题标题】:Using a config file in Vue.use在 Vue.use 中使用配置文件
【发布时间】:2021-02-09 13:34:23
【问题描述】:

在我的 index.ts 文件中,我正在使用 sitekey 配置我的 google recaptcha 组件:

Vue.use(VueReCaptcha, {
    siteKey: 'my_redacted_sitekey'
});

这发生在new Vue({ ... }) 语句之前。

我真的不希望在 index.ts 中硬编码 siteKey,因为我们必须重新部署它会改变它。

有没有办法将此值外包给配置文件并在此处使用它,或者这在new Vue({}) 语句之前是不可能的?

提前致谢

【问题讨论】:

    标签: typescript vue.js vuejs2


    【解决方案1】:

    您可以在/public 文件夹中放置一个配置文件并获取它。 (如果你把它放在/src 它会被编译。)

    随时从任何模块(包括main.js)中获取配置:

    axios.get('config.json').then(response => {
      const json = response.data;
      // do something with the config
    })
    

    例如。使用 axios

    记住要注意站点安全,因为它以这种方式位于公共文件夹中。

    也可能会在回调中加载 Vue 应用程序,但这会导致在加载文件之前出现空白页面。出于多种原因,使用加载消息启动应用程序比使用空白页面延迟它更好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多