vuejs / vue

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
http://v2.vuejs.org
MIT License
208.05k stars 33.69k forks source link

Improve diff intuition for components nested under plain elements #6659

Open ghost opened 7 years ago

ghost commented 7 years ago

Version

2.3.3

Reproduction link

https://jsfiddle.net/vitorDeng/50wL7mdz/63147/

Steps to reproduce

打开浏览器控制台,点击Run

What is expected?

其他v-if的元素不应该影响互不相干的组件

What is actually happening?

同级下,若前后使用了与包裹组件的元素一样的,并使用了v-if指令,则v-if指令会影响该组件不断创建和销毁

Jinjiang commented 7 years ago

主要是你那个发生改变的组件和 v-if 里的东西完全一样,diff 的时候难免会判断错误,但最起码也可以保持渲染出来的结果是一样的。临时解决办法就是在这些标签上加一些不一样的 attribute,就立刻工作正常了。


Translate into English:

Temporarily you can easily change:

<div><custom-component ref="componentPlugin"></custom-component></div>

into:

<div marked><custom-component ref="componentPlugin"></custom-component></div>

to avoid the re-render of the custom component in the middle.

Because the v-if component and the element above is all the same tag + without any props/attrs. So It's hard to the detect update details very exactly. But you can add special attribute to solve this.

Thanks.

yyx990803 commented 7 years ago

For now you can use a key on the div to mark it: https://jsfiddle.net/50wL7mdz/63293/

However this can be improved for sure.

ghost commented 7 years ago

谢谢

looser098 commented 7 years ago

看不懂哟

14780062668 commented 7 years ago

key is importatnt

chriscasola commented 7 years ago

I'll take a stab at this.