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

168
Vistas
El filtro VueJs debería mostrar la última palabra completa

He usado el filtro vue para limitar el texto a 100 caracteres. Estoy obteniendo salida como

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

Si ves la última palabra indu ... ,. No quiero tener una división de palabras en el medio con algunos caracteres de la palabra y puntos, sino que quiero que sea como la palabra completa y luego los puntos, como a continuación:

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

La palabra debe completarse después de 100 caracteres y luego ... debe agregarse.

A continuación se muestra el filtro Vue que he usado, ¿cómo puedo hacer que termine con la palabra completa y luego puntos en lugar de algunos caracteres de la última palabra?

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

0

1- obtener los primeros 100 caracteres

2- corte hasta el índice del siguiente espacio o final del texto.

 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)

  • No se recomienda el uso de substr . use substring en su lugar.
about 4 years ago · Juan Pablo Isaza Denunciar

0

Usando una expresión regular, se me ocurrió esta solución:

 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*$/, ''))

Básicamente, después de extraer los 100 primeros caracteres, uso una expresión regular para encontrar el último espacio seguido de caracteres que no son espacios y los elimino.

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