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

268
Vistas
How to delete the last two characters of a number if it contains a slash (vue.js)

I have a little problem with my code:

<template slot="popover">
  <img :src="'img/articles/' + item.id + '_1.jpg'">
</template>

Some of my item.id numbers (Exsample: 002917/1) have a slash in them. As a result, some images are not displayed. Now I would like to delet the last two charakters when there is an slash in the number. Is there a simple solution for this?

The slash should only be deleted at this point in the code and not in another place where the item.id is used.

I am very new to vue and javascript so please have mercy.

I am using the vue version 16.13.1

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could also use split. This will always give the correct result, even if there is no slash contained in the id.

<template slot="popover">
  <img :src="'img/articles/' + item.id.split('/')[0] + '_1.jpg'">
</template>
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can simply use slice here as:

const num = "002917/1";
const result = num.includes("/") 
                ? num.slice(0, -2) 
                : num;
console.log(result);

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