【问题标题】:Is it possible to have a custom function to encapsulate $t function?是否可以有一个自定义函数来封装 $t 函数?
【发布时间】:2020-07-18 15:36:56
【问题描述】:

我目前正在使用 Vue-i18n。

是否可以在另一个Vue.prototype函数中调用$t函数?

我想做的是有一个自定义函数$ba_t,它将在其中封装$t 函数。

可以吗?

谢谢。

【问题讨论】:

  • 你需要自定义函数$ba_t做什么?

标签: vue.js internationalization vue-component node-modules vue-i18n


【解决方案1】:

您必须创建一个插件:

const myPlugin = {
  install(Vue, options) {
    Vue.prototype.$ba_t = function(param) {
      return this.$t(param);
    };
  },
};
Vue.use(myPlugin);

这个插件创建一个调用旧方法的新方法。

【讨论】:

  • 这个答案解决了你的问题吗?请接受此答案,这将对其他人有所帮助。 How to accept an answer?
猜你喜欢
  • 2011-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-04
相关资源
最近更新 更多