Actually trying to check if file(image) exists to add it to render.
Confused that this code works
let i = 2;
let s = require('../../public' + this.cardData.image.optional_path + '-' + i + '.jpg');
and as a result s = Module
And this one produce an error
let i = 2;
let path = '../../public' + this.cardData.image.optional_path + '-' + i + '.jpg';
let z = require(path);
Error message:
Uncaught Error: Cannot find module '../../public/images/catgory1/images-2.jpg'
Did i missed something ?
question from:
https://stackoverflow.com/questions/65841055/image-require-with-variable-path-not-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…