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

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

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

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 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