Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
How do I call an object inside the Vue data as the value of an item?

So lets say I want to add this {{ $t('index-p1') }} inside the value of title.

items: [
        {
          icon: 'mdi-apps',
          title: 'Welcome',
          to: '/'
        },

I am using this for i18n and the data that the {{ $t('index-p1') }} contains is stored in a JSON file. It works just fine if I use it in a Vue template file, but not in data, I don't remember how to do this part.

almost 4 years ago · Santiago Trujillo
2 answers
Answer question

0

items should be defined as computed property, and access $t using this :

computed:{
   items(){
     return [
        {
          icon: 'mdi-apps',
          title: this.$t('welcome'),
          to: '/'
        }
     ]
   }
}
almost 4 years ago · Santiago Trujillo Report

0

You can use computed property and call it with this.$t:

const messages = {
  en: {
    message: {
      hello: 'hello world'
    }
  },
  fr: {
    message: {
      hello: 'bonjour'
    }
  }
}

const i18n = new VueI18n({
  locale: 'en', 
  messages, 
})

new Vue({
  i18n,
  computed: {
    text() { return this.$t("message.hello")}
  },
  methods: {
    setLang(lang) {
      i18n.locale = lang
    }
  }
}).$mount('#demo')
items: [
        {
          icon: 'mdi-apps',
          title: 'Welcome',
          to: '/'
        },
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-i18n/8.15.5/vue-i18n.min.js"></script>
<div id="demo">
  <button @click="setLang('fr')">fr</button>
  <button @click="setLang('en')">en</button>
  <p>{{ $t("message.hello") }}</p>
  {{ text }}
</div>

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!