Reputation: 8350
How to call a variable set in <script>
from the template using its string name?
For instance, in the example below, I'd like to call the foo
variable using table[0]
:
<template>
<div>
{{ table[0] }}
{{ table[1] }}
</div>
</template>
<script>
export default {
data() {
return {
foo: 'Hello World!',
bar: '大家好!',
table: ['foo', 'bar']
}
}
}
</script>
Upvotes: 1
Views: 374