How to add variables to require ()

using require to import a picture can only write the address of the picture? If the url of my picture is written in the json file, can I only get the picture in the following ways?

< hr >
{this.props.data.map((item, index) => {
                    const url = item.img;
                    var image = require("../../"+url+".jpg");
                    return <div key={item.key}>
                        <a href="-sharp" target="_blank">
                            <img src={image} className="img_logo"/>
                        </a>
                    </div>
                })}

in this case, json data cannot write its suffix

. < hr >
{
    "image":[{
      "key":"1",
      "img":"static/images/Logo"
    }]
  }

if I change it to "img": "static/images/Logo.jpg", and the require (".. /" + url) picture won"t show up.

< hr >

there is a problem. The url of the image in the json data file given to you by the user must have a suffix name, but the suffix name cannot be rendered if it is written in json. How should the code be modified?

Mar.19,2021

any Packer does static analysis, so what is in require must generally be a constant, or at least give enough information to identify the file type. If you delete the suffix ".jpg" , the things of require are determined entirely at run time, and the Packer will not know the type and will die naturally.

solution:
require.context learn about it. Just specify the file type as .jpg in advance

.

ides/dependency-management/-sharp%E5%B8%A6%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84-require-%E8%AF%AD%E5%8F%A5" rel=" nofollow noreferrer "> https://webpack.docschina.org.


have not seen the require source code, I have practiced a simple way. If there is a great god, you can explain the principle

.
var src = "/images/foo";
const FOO = require("${src}.png");
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea7e1c-1e94.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea7e1c-1e94.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?