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

169
Visualizações
VueJs filter should display last word full

I have used the vue filter to limit the text to 100 characters. I am getting output as

Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the indu ...

If you see the the last word indu ...,. I don't want to have a word breakup in between with few characters of the word and dots, instead I want it be like the complete word then dots, like below :

Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's ...

The word should complete after 100 characters then ... needs to appended.

Below is the Vue filter I have used, how can I make to end with complete word and then dots instead few characters of the last word?

 msg = "<p> Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing</p>\n" 

<h2 v-html="this.$options.filters.limitText(msg)" ></h2>

filters: {
  limitText: function (val) {
   if(val && (val.length > 100) {
     return (val.substr(0, 100) + ' ...')
   }
  return val;

  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

1- get first 100 char

2- slice till index of the next space or end of the text.

const msg = `Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing`

const LAST_INDEX = 99
let msgShort = msg.substring(0,LAST_INDEX)+msg.slice(LAST_INDEX,msg.indexOf(' ',LAST_INDEX))+'...'
console.log(msgShort)

  • substr is not recommended to use. use substring instead.
about 4 years ago · Juan Pablo Isaza Relatório

0

Using a Regular Expression, I came up with this solution:

const msg = `Tat is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing`

console.log(msg.substr(0, 100).replace(/\s\S*$/, ''))

Basically, after extracting the 100 first character, I use a regex to find the last space that is followed by non-space characters, and removes those.

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