我有两个组成部分:First.vue
和Second.vue
First.vue
在created()
上计算一些数据并将其存储Second.vue
通过computed
显示来自商店的数据,但得到:Cannot read property "total" of undefined
created() {
fetchHddInfo().then(info => {
this.$store.commit('updateMountedDrives', info)
})}
}
数据{{freeSize}}
显示在页面上,但是我第一次得到Cannot read property "total" of undefined
的计算结果是尝试从存储中获取数据(在数据从First.vue
到达之前)。
{{freeSize}}
...
computed: {
freeSize () {
return this.$store.state.AppData.mountedDrives.total.free
}
}
AppData.js
存储模块 mountedDrives
存储什么数据的示例:
{"total": { "free": 201136054272, "size": 2114488328192 }}
const state = {
mountedDrives: []
}
const mutations = {
updateMountedDrives (state, value) {
state.mountedDrives = value
}
}