Answer the question
In order to leave comments, you need to log in
How to return a copy of the value from an object in vuex store?
Here I monitor the metrics that are changing and if the condition works, I pass the metric objects to store mutationswatch: {
metric() {
if (this.metric) {
this.setSingleMetricNamesMap({
id: this.metric.id,
name: this.metric.name })
}
}
},
state
state getter I try to return the name of the metric by id which I pass from the componentsingleMetricNamesMap: {}
singleMetricNamesMap: state => id => state.singleMetricNamesMap[id]
state mutations Write metric objects to statesetSingleMetricNamesMap: (state, val) => {
state.singleMetricNamesMap[val.id] = val.name
},
The component where I pass a metric to the state getter id and try to return a copy of its name value from the store.singleMetricNamesMap object. But after reloading the page, I get undefined on the property of the object, that is, on id, and the names for the metrics appear only after the metric changes (for example, editing). Please tell me if I am returning a copy of the value from the store.singleMetricNamesMap object and how to display the names of the metrics immediately when the component is loaded <z-dash-tile-config-option
label="Metric"
:value="singleMetricNamesMap(value.metricId)"
>
Answer the question
In order to leave comments, you need to log in
after reloading the page I get undefined
$store.state.singleMetricNamesMap[value.metricId]
. If this is too long in your opinion, make a calculated property in the component that will represent singleMetricNamesMap.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question