kevinwarne / vue-balloon

A zoomable fixed balloon container. Useful for adding tutorial videos or other page specific content.
86 stars 11 forks source link

How to emit events when using multiple balloon #4

Closed minhtudapp closed 5 years ago

minhtudapp commented 5 years ago

I tried using events (written on the document) in multiple balloon (Ex: <template scope="balloon" @click="..."...) but it doesn't work. Is there anyway to solve the problem?

kevinwarne commented 5 years ago

Hmm not a perfect solution, but you should be able to add a nested element in the template and listen for events there. e.g.

<template scope="balloon">
  <div @click = 'doSomething'>
    Balloon Content
  </div>
</template>

Another option, albeit a bit more involved, is to listen for a click on the entire balloon set. Then you can reference the set to see which balloon is maximized if there is one.

<template>
    <balloon-set
      position = 'bottom-right'
      :balloons = 'balloons'
      @click.native = 'balloonSetClicked'
      ref = 'balloonSet'
    >
      <template scope = 'balloon'>
        Some Content Here
      </template>
    </balloon-set>
  </div>
</template>

<script>
  import { BalloonSet } from '../src/index'

  export default {
    components: {
      BalloonSet
    },

    data () {
      return {
        balloons: [
          /* Some balloon objects here */
        ]
      }
    },

    methods: {
      balloonSetClicked () {
        console.log(this.$refs.balloonSet.maximizedBalloon)
      }
    }
  }
</script>

Hope this helps! Cheers.

minhtudapp commented 5 years ago

Works! Thanks!