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

113
Views
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?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

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>

over 4 years ago · Santiago Trujillo Report

0

You need to use 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!