Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

reactjs - Image require with variable path not working

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...