I'm trying to add a random image (image-01.jpg, image-02.jpg, ... image-05.jpg) to an import
/require
request that I'm using with the data
option in Vue.js, the code looks like this:
<script>
const randomImage = `image-0${(Math.floor(Math.random() * 5) + 1)}.jpg`
export default {
data () {
return {
image: import('@/some/module/in/some/folder/\'' + randomImage + '\'')
}
}
}
</script>
But the error output I'm getting is:
Error: Cannot find module './'image-03.jpg'' at eval (eval at ./some/module/in/some/folder lazy recursive ^\.\/'.*'$
Is there a way to achieve this?
Many thanks in advance.
P.s. I've also tried the following:
<script>
const randomImage = `@/some/module/in/some/folder/winter-0${(Math.floor(Math.random() * 5) + 1)}.jpg`
export default {
data () {
return {
image: import(`${randomImage}`)
}
}
}
</script>
But get a similar error.
P.p.s. I should also add that I've tried using require
instead of import
.