「日常梳理」Vue2和Vue3 的区别

441 阅读1分钟

1. 分析Vue2和Vue3 的区别

数据响应式原理?

生命周期有区别?

vue-cli结构有变化

composition API有区别

面试升华 -「发布、订阅模式」和「观察者模式」的区别是什么?

「发布、订阅模式」和「观察者模式」的使用场景?

vue2和vue3的区别.png

响应式原理

  • vue2
采用的是「 Object.definProperty」进行「数据劫持」,结合「发布-订阅」模式进行数据双向绑定
  • vue3
采用的是「Proxy

生命周期

  • vue2
beforeCreate && created
beforeMount && mounted
beforeUpdate && updated
beforeDestroy && destroyed
activated && deactivated
  • vue3
setUp()
onBeforeMount && onMounted
onBeforeUpdate && onUpdated
onUnBeforeMount && onUnMounted
onActivated && onDeactivated

脚手架区别

  • vue3 去掉了config、build、static 文件,新增了pubilc文件,把html文件放入其中,src中新增了view文件