Heim  >  Fragen und Antworten  >  Hauptteil

Ist es möglich, eine Komponente anhand ihres Schlüssels zu lokalisieren?

Vue test-utils Gibt es Unterstützung für das Auffinden einer Komponente in einer Liste mithilfe ihres Schlüssels? Wenn nicht, gibt es eine andere Möglichkeit, in Vue als Liste generierte Komponenten zu finden?

P粉166779363P粉166779363205 Tage vor359

Antworte allen(1)Ich werde antworten

  • P粉156415696

    P粉1564156962024-03-28 00:57:35

    您无法使用 findComponent() 方法中的键查询组件。

    但是您可以获取列表中的所有组件,然后像常规数组一样过滤它们。 只需提供正确的条件即可找到您想要的项目(使用其道具、属性或其他内容)

    const items = wrapper.findAllComponents(MyListItem)
    const foundItem = items.wrappers.find(listItem => list.props('id') === 'theIdILookFor')
    

    Antwort
    0
  • StornierenAntwort