首先, 是 A, B 父子组件, 在 A 是父组件, B是子组件, 在 A 组件 action 中获取数据, 提交 mutations 存入 store, 在 b 中 mapState 出来, 在 cloneDeep 到 B 组件中的 data(){} 中的某个变量中. 问题在于我该如何知道 这个 mapstate 在何时获取到数据的, 因为在 A 中的 actions 是异步获取数据的, 在 B 中我知道 watch deep 能够知道, 问题是我只需要知道数据获取完成 mapState 出来有数据了的这一次, 而不需要知道每次变化, 代码不详细贴了, 见如下 demo
// A component
<div>
<b-component></b-component>
</div>
在 a 里 mapAction getData
// actions
export async function getData() {
let response = await xxx
commit(response)
}
//B components
export default {
data() {
return {
newStateData: {}
}
},
computed: {
...mapState({
demo: state => state.xxx.demo
})
},
created() {
//我想在数据开始监听的时候把 map 出来的这个 demo 给 cloneDeep 到 newStateData 中, 在得知数据被 map 进来之后我需要对数据进行一个操作, 并且这个操作只在数据被获取到之后初始化一次.
}
}
如上, 希望大神帮忙解惑下. 谢谢~~
你为什么要拷贝到newStateData中