Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
Vue youtube embed pause other video when playing another

I'm using this plugin https://www.npmjs.com/package/vue-youtube-embed to create two videos on a page in a vue app I am building. What I am trying to do is when playing one video pause the other. I was able to achieve this if the videos are in the same component using refs. My problem is each of the videos is nested inside a component and then placed on a parent page. Is there a way to have the same functionality but called from the parent? or a sibling communication?

I think this is more of a question of can you access a sibling components $ref? or is there a better approach possibly using store?

Same Component: (works as expected)

<div>
  <div class="l-text-image-band-media">
    <youtube 
      video-id="0mS0uT_wrhg" 
      @playing="stopOtherVideo('player2')" 
      ref="player1"
    ></youtube>
  </div>
  <div class="l-text-image-band-media">
    <youtube 
      video-id="0md0uT_wg7g" 
      @playing="stopOtherVideo('player1')" 
      ref="player2"
    ></youtube>
  </div>
</div>
methods: {
  stopOtherVideos(target) {
    this.$refs[target].player.stopVideo();
  },
}

Parent: (each component with videos nested in each)

<template>
  <div>
    <main class="main-content" id="main-content" tabindex="-1">
      <ResponsibilityByTheNumbers 
        is-video-component="true" 
        :text="handsOnText" 
      />   
      <ResponsibilityWhiteBandLeftText 
        is-video-component="true" 
        :showPrism="showPrism"
        :text="stemVideoBandText" 
      />
    </main>
  </div>
</template>

Video Component (only showing one) does not work

<youtube 
      video-id="0md0uT_wg7g" 
      @playing="stopOtherVideo('player1')" 
      ref="player2"
    ></youtube>

methods: {
  stopOtherVideos(target) {
    this.$refs[target].player.stopVideo();
  },
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda