Lak*_*eri 3 javascript vue.js vue-i18n
我想从字典这样设置默认属性:
props: {
title: {
type: String,
default: this.$t("basic.confirm"),
},
description: {
type: String,
}
}, ...
Run Code Online (Sandbox Code Playgroud)
这$t是vue-i18n,如果未在父类中定义标题,我想从字典中设置标题。但是我得到了错误:
未捕获的TypeError:this。$ t不是函数
类似的错误,如果我没有加载this。
未捕获的ReferenceError:未定义$ t
但是,如果我在mount方法中注销此值,则效果很好。
有没有从字典设置默认属性的解决方案?
提前致谢!
一种解决方案是将键或键的一部分作为默认道具,例如
title: {
type: String,
default: "basic.confirm", //or "confirm"
},
Run Code Online (Sandbox Code Playgroud)
并在模板中:
<h1>{{ $t(title) }}</h1> //or $t("basic." + title)
Run Code Online (Sandbox Code Playgroud)
编辑:您可以访问$ t内部函数
title: {
type: String,
default: function () {
return this.$t("basic.confirm")
}
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1304 次 |
| 最近记录: |