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

133
Views
¿Cómo puedo mostrar solo 30 caracteres como máximo en Vue.js?

Estoy tratando de hacer algo como esto.

Tengo este texto en una variable:

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

Y quiero usar una etiqueta para mostrar el texto, pero quiero mostrar solo unos pocos caracteres.

Para mi texto variable, quiero mostrar solo 5 caracteres.

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

Y quiero hacer algo como esto:

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

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

0

Realmente depende de la versión de Vue que estés usando. Vue 2 filtros compatibles (o pipes ):

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

Y entonces

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

En Vue 3, solo necesita crear una propiedad calculada (que también era posible en Vue 2, los filtros eran solo otra forma de hacerlo):

 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

Puede usar la expresión JavaScript en la plantilla vuejs.

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

0

Puedes usar 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!