Reputation: 341
I have something like this.
I want to import multi images with shorter code.
I tried to use a template string like this
But it seems to require not to show my image.
Upvotes: 0
Views: 144
Reputation: 186
You can use an index file to re-export all the images in folder
assets/images/forest/index.js
import layer0001 from './Layer_0001.png';
import layer0002 from './Layer_0002.png';
import layer0003 from './Layer_0003.png';
export { layer0001, layer0002, layer0003 };
and importing them as named import
import { layer0001, layer0002, layer0003 } from 'assets/images/forest';
or import everything
import * as forest from 'assets/images/forest';
which allow you to do a dynamic URL like
let layer = 'layer001';
backgroundImage: `url(${forest[layer]})`
Upvotes: 1