vue組件生命周期3步走:
掛載: beforeCreate => created => beforeMount => mounted
更新: beforeUpdate => updated
銷毀: beforeDestroy => destroyed
父子組件:
掛載: parent beforeCreate => parent created => parent beforeMount => child beforeCreate => child created => child beforeMount => child mounted => parent mounted
更新: parent beforeUpdate => child beforeUpdate => child updated => parent updated
銷毀: parent beforeDestroy => child beforeDestroy => child destroyed => parent destroyed
總結就是:
掛載時蛙吏,子組件是在父組件before mount后開始掛載土陪,并且子組件先mounted
更新時,子組件是在父組件before update后開始更新,子組件先于父組件更新
銷毀時纳鼎,子組件是在父組件before destroy后開始銷毀,并且是子組件先銷毀