【发布时间】:2020-01-01 18:56:36
【问题描述】:
我的 State 上有一个数组,我用 Getter 得到了它。问题是我无法复制这些数组。我正在尝试:
export default {
data() {
...,
termoSelected: false,
terms: []
},
computed: {
...mapGetters({
getPaymentUtils: 'negotiationaccount/getPaymentUtils', // It returns a Array
})
},
mounted() {
console.log(this.getPaymentUtils.rememberOptionsCash) // Shows data OK
this.terms = Array.from(this.getPaymentUtils.rememberOptionsCash)
},
methods: {
checkBoxChanged (index) { // Caled when checkbox is changed with v-model termoSelected
this.terms[index].selected = this.termoSelected // Trigger: Error: [vuex] do not mutate vuex store state outside mutation handlers.
}
}
}
我也试过.slice() 功能。但不起作用。所以我的问题是,当我使用 Getter 从 State 获取值时,无论如何我都无法复制数组。我该如何解决这个问题?
【问题讨论】:
-
在您尝试复制该数组之前,您确定您的数组已加载并具有价值?
-
@AniketPawar 是的,我用我用来检查它的控制台进行了编辑
-
我不知道 vuex,但我很确定我可以回答您是否可以将数组显示为 JSON 或将其登录到控制台时的样子。
标签: javascript arrays vue.js vuex