Search code examples
javascriptvue.jsvuejs2vue-i18n

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.


Solution

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

    computed:{
       items(){
         return [
            {
              icon: 'mdi-apps',
              title: this.$t('welcome'),
              to: '/'
            }
         ]
       }
    }