【发布时间】:2018-05-11 05:13:02
【问题描述】:
所以我不想像 vue i18next 库使用 $t 那样使用我的 mixin
<div>
<strong>{{ $t("loadbundle", {lang: this.lang}) }}</strong>
</div>
我可以在源代码中知道它是 mixin 中的计算属性
Vue.mixin({
computed: {
$t() {
const getKey = getByKey(this._i18nOptions, this.$i18n ? this.$i18n.i18next.options : {});
if (this._i18nOptions && this._i18nOptions.namespaces) {
const { lng, namespaces } = this._i18nOptions;
const fixedT = this.$i18n.i18next.getFixedT(lng, namespaces);
return (key, options) => fixedT(getKey(key), options, this.$i18n.i18nLoadedAt);
}
return (key, options) =>
this.$i18n.i18next.t(getKey(key), options, this.$i18n.i18nLoadedAt);
},
}
但我不知道他是如何让它像函数一样调用的,以及他是如何获取传入的参数的。
我不能使用方法,因为每次更新时它们都会执行。
【问题讨论】: