Vue.js面试突击

127 阅读1分钟

1. vue的生命周期函数有哪些?

  • beforeCreate
  • created
  • beforeMount
  • mounted
  • beforeUpdate
  • updated
  • beforeDestroy
  • destroyed

2. vue的通信方式有哪些?

  • props: 父子通信层层传递
  • $refs: 通过ID引用访问子组件实例
  • $parents/$children: 子组件访问父组件实例/获取当前实例的子组件
  • provide/inject: 祖先组件向后代组件注入依赖
  • eventBut: 在互通信的两组件中引入同一个新的vue实例
  • vuex

3. Vue.nextTick作用是什么?

  • 在DOM更新完成后调用传入的回调函数
  • 因为Vue中数据变化后,Vue将异步执行DOM更新

4. Vue双向数据绑定原理是什么?

  • 使用数据劫持 + 发布订阅模式实现
  • Vue2使用Object.defineProperty()
  • Vue3使用Proxy