一、页面跳转和生命周期 (面试必问)

1-1 A页面初次加载

  1. beforeCreate(){
  2. console.log("beforeCreate")
  3. },
  4. created(){
  5. console.log("created")
  6. },
  7. beforeMount(){
  8. console.log("beforeMount")
  9. },
  10. mounted(){
  11. console.log("mounted")
  12. }


1-2 A—>B

从A跳转到B页面 A页面

  1. beforeDestroy(){
  2. console.log("beforeDestroy")
  3. },
  4. destroyed(){
  5. console.log("destroyed")


1-3 B—>A

  1. # B页面跳转回A页面,A页面以下生命周期会执行
  2. beforeCreate(){
  3. console.log("beforeCreate")
  4. },
  5. created(){
  6. console.log("created")
  7. },
  8. beforeMount(){
  9. console.log("beforeMount")
  10. },
  11. mounted(){
  12. console.log("mounted")
  13. }



二、生命周期 updated

  1. beforeUpdate,updated什么时候执行
  2. 1data中的数据更新的时候
  3. 2、模板中要使用data中的数据

三、beforeDestory,destoryed

  1. # A-->B A页面跳转到B页面
  2. 1beforeCreate B
  3. 2created B
  4. 3beforeMounted B
  5. 4beforeDestroy A
  6. 5destroyed A
  7. 6mounted B


四、DOM和生命周期

只能在mounted生命周期函数中获取DOM