gpt4 book ai didi

vue.js - Vue Mixin 计算函数传递参数

转载 作者:行者123 更新时间:2023-12-02 03:26:21 24 4
gpt4 key购买 nike

所以我不想像 vue 一样使用我的 mixin i18next库使用 $t

<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);
},
}

但我不明白他如何能够像函数一样调用它以及他如何获取传入的参数。

我无法使用方法,因为每次更新时它们都会被执行。

最佳答案

注意return (key, options) => ... 位:返回一个函数!因此,您上面编写的模板调用首先检索计算属性(函数)的值,然后使用一些参数调用它。

实际上,获取 $i18n 对象的所有前期准备工作都已完成一次,但如果任何参数发生变化,翻译仍然可能会发生变化(例如 this.lang)。

关于vue.js - Vue Mixin 计算函数传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com