title: Set a variable inside a v-for loop on Vue JS
body: <p>I have a v-for loop with vue.js on a SPA and I wonder if it's posible to set a variable at the beginning and then just print it everytime you need it, because right now i'm calling a method everytime i need to print the variable.</p>
  
  <p>This is the JSON data.</p>
  
  <pre><code>{
  "likes": ["famiglia", "ridere", "caffè", "cioccolato", "tres leches", "ballare", "cinema"],
  "dislikes":["tristezze", "abuso su animali", "ingiustizie", "bugie"]
  </code></pre>
  
  <p>}</p>
  
  <p>Then I use it in a loop:</p>
  
  <pre><code>&lt;template&gt;
  &lt;div class="c-interests__item" v-for="(value, key) in interests" :key="key" :data-key="key" :data-is="getEmotion(key)" &gt;
  
  // NOTE: I need to use the variable like this in different places, and I find myself calling getEmotion(key) everythime, is this the way to go on Vue? or there is another way to set a var and just call it where we need it?
  
  &lt;div :class="['c-card__frontTopBox', 'c-card__frontTopBox--' + getEmotion(key)]" ...
  &lt;svgicon :icon="getEmotion(key) ...
  
  &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  import interests from '../assets/json/interests.json'
  ... More imports
  
  let emotion = ''
  
  export default {
    name: 'CInfographicsInterests',
    components: {
      JSubtitle, svgicon
    },
    data () {
      return {
        interests,
        emotion
      }
    },
    methods: {
      getEmotion (key) {
        let emotion = (key === 0) ? 'happy' : 'sad'
        return emotion
      }
    }
  }
  &lt;/script&gt;
  
  // Not relevanty to the question
  &lt;style lang='scss'&gt;
  .c-interests{...}
  &lt;/style&gt;
  </code></pre>
  
  <ol>
  <li><p>I tried adding a prop like :testy="getEmotion(key)" and then { testy } with no luck...</p></li>
  <li><p>I tried printing { emotion } directly and it doesn't work</p></li>
  </ol>
  
  <p>So, there is anyway to acomplish this or should i stick calling the method every time? </p>
  
  <p>Thanks in advance for any help.</p>