【发布时间】:2020-04-07 22:51:47
【问题描述】:
我的代码是这样的:
<template>
...
...
</template>
<script>
export default {
...
methods: {
...mapActions([
'getDataDoctor',
'getDataSchedule'
]),
async visibilityChanged(isVisible, entry, item) {
let param = {
hospitalId: item.hospital_id,
doctorId: item.doctor_id
}
await this.getDataSchedule(param)
let data = this.dataDoctor
for (let key in data) {
this.$set(data[key].find(e => e.doctor_id === item.doctor_id && e.hospital_id === item.hospital_id), 'schedule', this.dataSchedule.schedule)
}
}
},
computed: {
...mapState({
dataDoctor: state => state.dataStore.dataDoctor,
dataSchedule: state => state.dataStore.dataSchedule
}),
},
}
</script>
如果我 console.log(this.dataDoctor),结果是这样的:
或者你可以查看 this.dataDoctor 这个:https://pastebin.com/yGjsTBjX
this.dataDoctor 是来自 vuex 存储的状态。我想在那里增加新的价值。名字叫schedule
我喜欢这样。但是存在这样的错误:
无法在未定义、null 或原始值上设置反应属性:未定义
Uncaught (in promise) TypeError: Cannot use 'in' operator to search 'schedule' in undefined
我该如何解决这个问题?
【问题讨论】:
标签: vue.js multidimensional-array vuejs2 vue-component vuex