Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
How can I use the method from other component

I want use the method 'pause()' in the component 'vue-count-to',but the webstorm tips Unresolved function or method pause() .How can I use the method in 'vue-count-to'?Thank you

<template>
  <div>
  <countTo ref="countTo1" :startVal='startVal' :endVal='endVal' :duration='3000'>

  </countTo>
  <input type="text" v-model="endVal">
    <Button v-on:click="handleClick" >reset</Button>
  </div>
</template>

<script>
import CountTox from 'vue-count-to';
export default {
  components: {
    countTo: CountTox},
  data () {
    return {
      startVal: 0,
      endVal: 2017,
      autoplay: false
    }
  },
  methods: {
    handleClick() {
      this.$refs.countTo1.pause();
    }
  }
}
</script>
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

you can use $root.$emit() and $root.$on()

const componentA = {
  template: `
    <button @click="callMethodInComponentB">
      call method in component-b
    </button>
  `,
  methods: {
    callMethodInComponentB() {
      this.$root.$emit('call-to-component-b', 2);
    }
  }
}

const componentB = {
  template: `
    <h1>Value: {{ value.toString() }}</h1>
  `,
  data(){
    return {
      value: 0
    }
  },
  methods: {
    plus(add) {
      this.value += add
    }
  },
  mounted() {
    this.$root.$on('call-to-component-b', add => {
       this.plus(add)
    });
  }
};


new Vue({
  el: '#app',
  components: {
    componentA,
    componentB
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<main id="app">
   <component-a></component-a>
   <component-b></component-b>
</main>

over 4 years ago · Santiago Trujillo Denunciar

0

define the method in App.vue and access it from probs and emit

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda