有史以来第一次合作,Vue.js不知道什么是什么$t。例如我有这样的人的代码:
<li class="category-filter__back">
<button
class="category-filter__button"
@click="back(categoryPath)">
{{ $t(backButtonText) }} <<<<<<<< what is this $t?
</button>
</li>
Run Code Online (Sandbox Code Playgroud)
似乎找不到任何具体答案。
Yuc*_*uci 10
这里的 $t 应该是Vue I18n的扩展 Vue 实例方法。
模板
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-i18n/dist/vue-i18n.js"></script>
<div id="app">
<!-- string literal -->
<p v-t="'hello'"></p>
<!-- keypath biniding via data -->
<p v-t="path"></p>
<!-- extended Vue instance method -->
<p>{{ $t("wait") }}</p>
<button @click="changeLocale()">
{{ $t("buttonText") }}
</button>
</div>
Run Code Online (Sandbox Code Playgroud)
脚本
new Vue({
el: '#app',
i18n: new VueI18n({
locale: 'en',
messages: {
en: { hello: 'hi there', bye: 'see you later', wait: 'just a minute', buttonText: 'Change to Chinese Locale' },
cn: { hello: '??', bye: '??', wait: '????', buttonText: '???????' }
}
}),
data: { path: 'bye' },
methods: {
changeLocale() {
this.$i18n.locale = this.$i18n.locale === 'en' ? 'cn' : 'en'
}
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7845 次 |
| 最近记录: |