I'm trying to work out how I can use a variable (prop) as part of an array map function.
Basically I have this code:
var result = this.$store.getters['example/store'].map(a => a.fixed_column)
and I want fixed_column to be able to be a variable, allowing me to reuse this component in lots of places depending what column name is passed in as a prop.
I tried
.map(a => a.{this.category})
and other various syntax variations of that - but couldnt get it to work.
What I want to be able to do is something like this:
<my-component category="example_column"></my-component>
and have the array sum up example_column
This is my full vue component if needed:
<template>
<div>
<p>Pending count: {{ pending }}</p>
</div>
</template>
<script>
export default {
props: {
category: {},
},
computed: {
pending() {
var result = this.$store.getters['example/store'].map(a => a.fixed_column);
return result.reduce((a, b) => a + b, 0);
}
},
}
</script>
categoryprop?a[this.category]?categorywould be a string I can set on the component to allow me to reuse it.