2👍
✅
You can set a lang
variable to something like 'en'
and use title[lang]
. This will be the same as calling title.en
.
new Vue({
el: '#app',
data: {
lang: 'en',
title: {
en: 'Hello',
es: 'Hola'
}
}
});
<div id="app">
<ul>
<li @click="lang = 'en'">English</li>
<li @click="lang = 'es'">Spanish</li>
</ul>
<h1>{{ title[lang] }}</h1>
</div>
Source:stackexchange.com