鍍金池/ 問答/HTML/ vuejs 數(shù)據(jù)監(jiān)聽操作

vuejs 數(shù)據(jù)監(jiān)聽操作

首先, 是 A, B 父子組件, 在 A 是父組件, B是子組件, 在 A 組件 action 中獲取數(shù)據(jù), 提交 mutations 存入 store, 在 b 中 mapState 出來, 在 cloneDeep 到 B 組件中的 data(){} 中的某個(gè)變量中. 問題在于我該如何知道 這個(gè) mapstate 在何時(shí)獲取到數(shù)據(jù)的, 因?yàn)樵?A 中的 actions 是異步獲取數(shù)據(jù)的, 在 B 中我知道 watch deep 能夠知道, 問題是我只需要知道數(shù)據(jù)獲取完成 mapState 出來有數(shù)據(jù)了的這一次, 而不需要知道每次變化, 代碼不詳細(xì)貼了, 見如下 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() {
         //我想在數(shù)據(jù)開始監(jiān)聽的時(shí)候把 map 出來的這個(gè) demo 給 cloneDeep 到 newStateData 中, 在得知數(shù)據(jù)被 map 進(jìn)來之后我需要對(duì)數(shù)據(jù)進(jìn)行一個(gè)操作, 并且這個(gè)操作只在數(shù)據(jù)被獲取到之后初始化一次.
    }
}

如上, 希望大神幫忙解惑下. 謝謝~~

回答
編輯回答
神經(jīng)質(zhì)

你為什么要拷貝到newStateData中

2017年12月1日 09:40
編輯回答
純妹

可以把cloneDeep這個(gè)動(dòng)作放在子組件的created 方法里面。

2017年8月8日 14:53