0

I have a question:

How can i put a variable inside a interpolation?

For exemple:

<template>

<span>{{item.VARIABLE.name}}</span>

</template>


<script>
let VARIABLE = 'somenthing'
</script>

My "item.name" comes from a JSON and i need to put a variable in the middle.

user41495
  • 35
  • 1
  • 1
  • 4

1 Answers1

1

As @Bert said in the first comment, you can access that by using the item[variable].name style of access.

If it's not clear, the variable has to be defined in Vue's data, otherwise Vue cannot see it and the access yields an error.

So basically:

{{ item[place].name }} // Pete

works if your Vue's data looks something like:

data: {
  item: {
    a: {
      name: "Pete"
    }
  },
  place: "a"
} 
pate
  • 4,937
  • 1
  • 19
  • 25