Problem Description: the error cannot find mouse ‘is reported when the picture path is introduced
const listArr = [
{
"title": "title 1",
"icon" : "./../../img/icon1.png"
},
{
"title": "title 2",
"icon" : "./../../img/icon2.png"
},
{
"title": "title 3",
"icon" : "./../../img/icon3.png"
},
];
listArr.map((item,index) => {
return (
<li key={index}>
<img src={require(item.icon)} alt="" /> //error Cannot find moudle '.'
{item.title}
</li>
)
})
Cause analysis: path variables cannot be written directly in require, but need to be written in path format
Path variables cannot be written directly in require. They need to be written in path format, which has been tested (<img src={require(`./../../img/${item.icon}`)} alt=”” />) That’s OK
Solution: < img src={require(`./../../img/${item.icon}`)} alt=”” />
const listArr = [
{
"title": "title 1",
"icon" : "icon1.png"
},
{
"title": "title 2",
"icon" : "icon2.png"
},
{
"title": "title 3",
"icon" : "icon3.png"
},
];
listArr.map((item,index) => {
return (
<li key={index}>
<img src={require(`./../../img/${item.icon}`)} alt="" />
{item.title}
</li>
)
})
Read More:
- [Solved] webpack.config.js configuration encountered Error: Cannot find module’@babel/core’&&Cannot find module’@babel/plugin-transform-react-jsx’
- Attempted import error: ‘mobx-react‘ does not contain a default export (imported as ‘observer‘).
- How to Solve “Status bar could not find cached time string image. Rendering in-process.” in Xcode
- mainfest Image Error: (img/icons/andriod-chrome-192×192.png)Download error or resource isn’t a vaild image
- [Solved] react Error: Can‘t perform a React state update on an unmounted component
- React Hook “useState“ is called in function “xxx“ which is neither a React function component or
- [Solved] OpenGL PowerVR SDK Compiling Error: Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB)
- How to Fix Error Cannot find command ‘git‘ – do you have ‘git‘ installed and in your PATH?
- Crop the cropper image .toBlob() error: $(“#image”).cropper(‘getCroppedCanvas’).toBlob( function (blob){})
- Springboot configuration project access path URL root path
- [Solved] Docker Delete Image Error: Error: No such image
- ValueError: Input 0 of node import/save/Assign was passed float from import/beta1_power:0 incompatib
- Taro Use React Hooks Error: TypeError: Object(…) is not a function
- [Solved] Vite Bulk Import import.meta.glob Error: ERR_ABORTED 403 (Forbidden)
- package golang.org/x/net/XXX: unrecognized import path “golang.org/x/net/xxx“…
- Keras-nightly Import package Error: cannot import name ‘Adam‘ from ‘keras.optimizers‘
- NPM install -g create-react-app [How to Solve]
- [Solved] React Native Red screen Error: Unable to load script from assets
- OpenCV4 Error: imread(argv[1], CV_LOAD_IMAGE_COLOR);
- [Solved] C# Access Mongodb Database Error: command find failed: Command find requires authentication