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

125
Views
How can I display only 30 characters maximum in Vue.js?

I'm trying to do something like this.

I have this text in a variable :

let text = 'hey this is a super long phrase'

And I want to use a label to display the text, but I want to display only a few characters.

For my variable text I wanna display only 5 characters.

<label>{{text}}</label> //display the full text

And I wanna do something like this :

<label>{{text}}</label> //display only hey t

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

0

It really depends on which version of Vue you're using. Vue 2 supported filters (or pipes):

filters: {
  short: function (value) {
    return value.substr(0, 5); // just an example
  }
}

And then

<label>{{ text | short }}</label>

In Vue 3 you just need to create a computed property (which was also possible in Vue 2, filters were just another way for that):

computed: {
  shortText() {
    return this.text.substr(0, 5)
  }
}

// if you're using Composition API
const shortText= computed(() => text.value * 2); // if text is another ref
<label>{{ shortText }}</label>
about 4 years ago · Juan Pablo Isaza Report

0

You can use JavaScript expression in vuejs template.

<label>{{text.substring(0,5)}}</label>
about 4 years ago · Juan Pablo Isaza Report

0

You can use String.prototype.slice()

document.body.innerHTML = 'hey this is a super long phrase'.slice(0, 5)

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!