Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

You can use JavaScript expression in vuejs template.

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

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda