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

238
Views
How to change word endings in vue?

How to change word endings in vue? For example: 1 day/3 days, 1 detail/5 details

In js code will be like:

function declOfNum(number, titles) {
 let cases = [2, 0, 1, 1, 1, 2];
 return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? 
 number % 10 : 5]];
}

Im new with vue, sorry for simple question :]

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Well, This is really straightforward. you can make a method for that.

 getTitle(number) {
    return `${number} detail${number > 1 ? 's' : ''}`;

}

then in your template just call this method by passing the number like this.

You might also pass title as well if you have other titles as well than detail.

{{ getTitle(2) }}

about 4 years ago · Juan Pablo Isaza Report

0

You can try to use computed property with data object:

var app = new Vue({ 
  el: '#app',
  data() {
    return {
      titles: ['detal', 'details'],
      num: 2
    }
  },
  computed: {
    detail: function() {
      if (this.num > 1) return this.titles[1]
      return this.titles[0]
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <p>{{ detail }}</p>
  <input v-model="num" type="number" />
</div>

about 4 years ago · Juan Pablo Isaza 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!