今天在使用vue框架搭建环境时,遇到这个错误提示: [Vue warn]: Attribute "id" is ignored on component <div> because the component is a fragment instanc 这个提示的原因是使用 vue-router 和 vue-loader 插件的时候在最外面那个 template 里面,所有内容的外面没有使用一个div包起来. 如果没有使用div或者其他的元素包起来,vue-router 跳…
网上有很多博客讲到,React.Vue里的key,与 Virtual DOM 及 DOM diff 有关, 可以用来唯一标识DOM节点,提高diff效率,云云. 这大致是对的,但是,大多讲得语焉不详,像是在背答案. 具体怎么个提效法?为什么说用数组下标当作key是"反模式"?讲了一堆,能不能来个眼见为实,show me the code? 本文以React为例,尝试稍微刨一刨,但又不刨到太底层,以足够帮助理解为度. 1. VNode diff 首先介绍 Virtual DOM 结点(后…