Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

You can use JavaScript expression in vuejs template.

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda