M
M
Martovitskiy2017-09-17 11:50:31
Vue.js
Martovitskiy, 2017-09-17 11:50:31

How to click a button using $emit vue.js?

Can't forward click to child element. Reading documentation and don't understand https://vuejs.org/v2/guide/
index.vue

<template>
    <div class="fullpage-container">
        <div class="page-home">
            <div class="button-group">
                <b-button-group vertical>
                    <b-button type="button"  v-bind:class="[{active:index ==0}]" @click="moveTo(2)">   // кликнуть эту кнопку
                        button
                    </b-button>
                </b-button-group>
            </div>
            <div class="fullpage-wp" v-fullpage="opts" ref="example">
                ...
                <div class="page">
                    <logo></logo>
                </div>
                ...
            </div>
        </div>
    </div>
</template>
<script>
import Logo from '~/components/Logo.vue'

export default {
  data () {
    var that = this
    return {
      index: 0,
      opts: {
        start: 0,
        dir: 'v',
        duration: 500,
        beforeChange: function (prev, next) {
             that.index = next
        },
        afterChange: function (prev, next) {
        }
      }
    }
  },
  methods: {
    moveTo (index) {
      this.$refs.fullpage.$fullpage.moveTo(index, true)
    }
  },
  components: {
    Logo
    ...
  }
}
</script>

logo.vue
<template>
    <b-button v-on.click="trigger">click</b-button>  // этой кнопкой
</template>
<script>
export default {
   data () {
....
  },
  methods: {
        trigger: function () {
    	      // this.$emit
      }
  }
}
</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem0071, 2017-09-17
@Martovitskiy

In the main component:
In the logo:

trigger: function () {
    this.$emit('handleAction')
}

True, I didn’t understand what index you want to get there, but the forwarding is done like this.
If you want to forward some other variable, then you need to do this:
trigger: function () {
    this.$emit('handleAction', someParam)
}

M
Max, 2020-10-03
@EddiePoe

@click.native="<blockquote>Метод/Функция/...</blockquote>"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question