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

179
Vistas
Vue.js call method in the data

I am new to vue.js and I want to call a method in the data so something like this:

data() {
        return {
            title: capitalizeFirstLetter('title'),
        };
    },

and my vue mixin which I imported to my main.js

Vue.mixin({
  methods: {
    capitalizeFirstLetter(str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
    }    
  }
})

but this doesnt work, I cant call capitalizeFirstLetter in the data. Is it possible to call a method in data?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Please ensure that you have registered the mixin in the component using mixin property in component.

After that you can access capitalizeFirstLetter method defined inside the mixin using this.capitalizeFirstLetter

Working fiddle

const myMixin = {
  methods: {
    capitalizeFirstLetter(str) {
      return str.charAt(0).toUpperCase() + str.slice(1);
    }
  }
}

new Vue({
  el: "#app",
  mixins: [myMixin],
  data() {
    return {
      title: this.capitalizeFirstLetter('title'),
    };
  },
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  {{ title }}
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to use this

title: this.capitalizeFirstLetter('title'),
about 4 years ago · Juan Pablo Isaza 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