diff --git a/docs/api/index.md b/docs/api/index.md index 545884761..97200c9f1 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -1267,13 +1267,13 @@ const RootComponent = { template: '' } const wrapper = mount(RootComponent) -const rootByCss = wrapper.findComponent('.root') // => finds Root -expect(rootByCss.vm.$options.name).toBe('Root') +const rootByCss = wrapper.findComponent('.root') // => finds Child +expect(rootByCss.vm.$options.name).toBe('Child') const childByCss = wrapper.findComponent('.child') -expect(childByCss.vm.$options.name).toBe('Root') // => still Root +expect(childByCss.vm.$options.name).toBe('Child') // => still Child ``` -The reason for such behavior is that `RootComponent` and `ChildComponent` are sharing same DOM node and only first matching component is included for each unique DOM node +The reason for such behavior is that `RootComponent` and `ChildComponent` are sharing same DOM node and only one component is returned for each unique DOM node: on the root element of the wrapper you're searching from, it is the component rendered at the root (here `ChildComponent`), elsewhere it is the first matching component. ::: :::info WrapperLike type when using CSS selector diff --git a/docs/fr/api/index.md b/docs/fr/api/index.md index 66df618ff..68a5c62d9 100644 --- a/docs/fr/api/index.md +++ b/docs/fr/api/index.md @@ -1213,13 +1213,13 @@ const RootComponent = { template: '', }; const wrapper = mount(RootComponent); -const rootByCss = wrapper.findComponent('.root'); // => trouve Root -expect(rootByCss.vm.$options.name).toBe('Root'); +const rootByCss = wrapper.findComponent('.root'); // => trouve Child +expect(rootByCss.vm.$options.name).toBe('Child'); const childByCss = wrapper.findComponent('.child'); -expect(childByCss.vm.$options.name).toBe('Root'); // => toujours Root +expect(childByCss.vm.$options.name).toBe('Child'); // => toujours Child ``` -La raison de ce comportement est que `RootComponent` et `ChildComponent` partagent le même nœud DOM et que seul le premier composant correspondant est inclus pour chaque nœud DOM unique. +La raison de ce comportement est que `RootComponent` et `ChildComponent` partagent le même nœud DOM et qu'un seul composant est retourné pour chaque nœud DOM unique : sur l'élément racine du wrapper à partir duquel vous cherchez, c'est le composant rendu à la racine (ici `ChildComponent`), ailleurs c'est le premier composant correspondant. ::: :::info Type WrapperLike en utilisant un sélecteur CSS diff --git a/docs/zh/api/index.md b/docs/zh/api/index.md index 5255ae644..6639dd655 100644 --- a/docs/zh/api/index.md +++ b/docs/zh/api/index.md @@ -1214,13 +1214,13 @@ const RootComponent = { template: '' } const wrapper = mount(RootComponent) -const rootByCss = wrapper.findComponent('.root') // => finds Root -expect(rootByCss.vm.$options.name).toBe('Root') +const rootByCss = wrapper.findComponent('.root') // => finds Child +expect(rootByCss.vm.$options.name).toBe('Child') const childByCss = wrapper.findComponent('.child') -expect(childByCss.vm.$options.name).toBe('Root') // => still Root +expect(childByCss.vm.$options.name).toBe('Child') // => still Child ``` -这种行为的原因是 `RootComponent` 和 `ChildComponent` 共享相同的 DOM 节点,并且每个唯一的 DOM 节点只包含第一个匹配的组件。 +这种行为的原因是 `RootComponent` 和 `ChildComponent` 共享相同的 DOM 节点,并且每个唯一的 DOM 节点只返回一个组件:在你进行搜索的包装器的根元素上,返回的是在根部渲染的组件 (此处为 `ChildComponent`),在其他位置返回的是第一个匹配的组件。 ::: :::info 使用 CSS 选择器时的 WrapperLike 类型