Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Método de llamada Vue.js en los datos

Soy nuevo en vue.js y quiero llamar a un método en los datos, así que algo como esto:

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

y mi vue mixin que importé a mi main.js

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

pero esto no funciona, no puedo llamar a capitalizeFirstLetter en los datos. ¿Es posible llamar a un método en datos?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Asegúrese de haber registrado el mixin en el componente usando la property mixin en el componente.

Después de eso, puede acceder al método capitalizeFirstLetter definido dentro del mixin usando this.capitalizeFirstLetter

violín de trabajo

 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>

over 4 years ago · Santiago Trujillo Report

0

Necesitas usar this

 title: this.capitalizeFirstLetter('title'),
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!