I'm importing an array called CHART_CARDS
in a Vue component. This is meant to provide the initial state for another array, called chartCards
, which a user can change.
import { CHART_CARDS } from '~/constants/chartCards'
...
export default {
data(){
return {
chartCards: []
}
},
async created(){
if (this.$auth.user.settings && this.$auth.user.settings.length) {
this.chartCards = this.$auth.user.settings
} else {
this.chartCards = CHART_CARDS
}
}
}
So the data property chartCards is either taken from the imported variable or from a pre-existing database table.
Here's where things get weird: I have a method called reset, which is supposed to restore the chartCards variable to the value of the imported array:
async reset () {
console.log('going to reset. CHART_CARDS looks like:')
console.log(CHART_CARDS)
this.chartCards = CHART_CARDS
await this.updateCards()
console.log('chart cards after updating:')
console.log(this.chartCards)
}
Somehow, CHART_CARDS
is also changed when chartCards
is updated. The two console logs above print the same array, so the reset doesn't work. CHART_CARDS
is changed nowhere else in the code; all references to CHART_CARDS
are shown in the above code. How is its value being updated?