Vue Study

Vue3 - LifeCycle

eddie0329 2020. 10. 30. 08:50
λ°˜μ‘ν˜•

πŸ“Œ λͺ©μ°¨

  • Introduction
  • Life cycle in vue
  • Hook inside setup
  • Conclusion
  • Reference

πŸ“Œ Introduction

μ•ˆλ…•ν•˜μ„Έμš”. μ˜€λŠ˜μ€ Vue3에 μƒˆλ‘œμš΄ life cycle에 λŒ€ν•΄μ„œ μ•Œμ•„λ³΄λ €κ³  ν•©λ‹ˆλ‹€. ν•΄λ‹Ή μ½”λ“œλŠ” μ—¬κΈ°μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

πŸ“Œ Hook inside setup

λ¨Όμ € μƒˆλ‘­κ²Œ 바뀐 것듀에 λŒ€ν•΄μ„œ Vue3 곡식 λ¬Έμ„œμ— μžμ„Έν•˜κ²Œ λ‚˜μ™€μžˆμŠ΅λ‹ˆλ‹€.

λ„€ 이제 beforeCreatedλ‚˜ createdλŠ” ꡳ이 선언을 ν• ν•„μš”κ°€ μ—†μ–΄ μ‘ŒμŠ΅λ‹ˆλ‹€.

import { onMounted, nextTick, onUpdated } from 'vue';

export default {
  name: 'App',
  components: {
    HelloWorld
  },
  setup() {
    console.log('before created');
    console.log('created');
    nextTick(() => {
      console.log('nextTick');
    });
    onMounted(() => {
      console.log('onMounted');
    });
    onUpdated(() => {
      console.log('update');
    });

    // RESULT:
    // before created
    // created
    // onMounted
    // nextTick
  }
};

πŸ“Œ Conclusion

μƒˆλ‘œμš΄ life-cycle-api에 λŒ€ν•΄μ„œ μ•Œμ•„λ³΄μ•˜μŠ΅λ‹ˆλ‹€. μ΄λ ‡κ²Œ λ§Žμ€ κΈ°λŠ₯듀이 μͺΌκ°œμ Έμ„œ μž¬μ‚¬μš©μ„±μ΄ 정말 많이 증가할 것 κ°™μŠ΅λ‹ˆλ‹€. 그럼 λ‹€μŒ ν¬μŠ€νŒ…μ—μ„œ λ§Œλ‚˜μš”~~ πŸŽ‰

πŸ“Œ Reference

λ°˜μ‘ν˜•