Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1267,13 +1267,13 @@ const RootComponent = {
template: '<child-component class="root" />'
}
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
Expand Down
8 changes: 4 additions & 4 deletions docs/fr/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1213,13 +1213,13 @@ const RootComponent = {
template: '<child-component class="root" />',
};
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&nbsp;: 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
Expand Down
8 changes: 4 additions & 4 deletions docs/zh/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1214,13 +1214,13 @@ const RootComponent = {
template: '<child-component class="root" />'
}
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 类型
Expand Down
Loading