1. 程式人生 > 其它 >vue和react生命週期

vue和react生命週期

react
componentWillMount(){ console.log('元件將要掛載','componentWillMount'); } componentDidMount(){ console.log('元件已經掛載','componentDidMount'); } componentWillReceiveProps(){ console.log('父元件傳遞的屬性更新了', 'componentWillReceiveProps'); } shouldComponentUpdate(){ console.log('元件是否應該更新,需要返回布林值', 'shouldComponentUpdate'); } componentWillUpdate(){ console.log('元件將要更新', 'componentWillUpdate'); } componentDidUpdate(){ console.log('元件已經更新', 'componentDidUpdate'); } componentWillUnmount(){ console.log('元件已經銷燬', 'componentWillUnmount'); }

vue3.0
 onMounted(() => {       console.log('子元件onMounted')     })     onBeforeMount(() => {       console.log('子元件onBeforeMount')     })     onBeforeUpdate(() => {       console.log('子元件onBeforeUpdate')     })     onUpdated(() => {       console.log('子元件onUpdated')     })     onBeforeUnmount(() => {       console.log('子元件onBeforeUnmount')     })     onUnmounted(() => {       console.log('子元件onUnmounted')     })     onErrorCaptured(() => {       console.log('子元件onErrorCaptured')     })