violet0sea / note

can not open gist, so write here
0 stars 0 forks source link

React和Vue的区别 #19

Open violet0sea opened 6 years ago

violet0sea commented 6 years ago

共同点:

  1. Component based architecture,都是已组件为基础构建视图
  2. 使用Virtual DOM && DOM Diff
  3. 相似的概念, props | state | lifeCycle ...
violet0sea commented 6 years ago

不同点:

  1. Vue使用单文件的组件格式,React推荐jsx语法;
  2. Vue使用Object.defineProperty()定义getter()|setter()方法,来劫持数据变化,强调数据可变性;React使用setState来改变数据,强调数据的不可变,never&ever使用this.state.key = value去修改状态;React存在单一节点状态改变,会引发子组件的不必要更新,需要使用PureComponent|ShouldComponentUpdate|React.memo去优化
  3. Vue存在大量的api需要学习,好处是在合适的时机采用特定的api不会对性能造成影响,React提供的概念相对较少,但是要写出符合预期的代码需要对api深入理解