Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
How to replace a slash in 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 have a slash in them. As a result, some images are not displayed. Now I would like to replace the slash with an underline or delete it, if a slash occurs in the item.id numbers. Is there a simple solution for this?

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

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

you can use a computed property and replace slashes by dashes with replace and a regex:

<template slot="popover">
  <img :src="`img/articles/${itemId}_1.jpg`">
</template>

<script>
...
  computed: {
    itemId: function(){
        return this.item.replace(/\//g, '-');
    }
  }
...
</script>

here's a test fiddle : https://jsfiddle.net/pqfvba6n/

over 4 years ago · Santiago Trujillo Report

0

Use replace (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)

<template slot="popover">
  <img :src="'img/articles/' + item.id.replace(/\//g, '_') + '_1.jpg'">
</template>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!