gpt4 book ai didi

javascript - 将图像数组添加到弹出窗口

转载 作者:行者123 更新时间:2023-12-02 22:07:13 25 4
gpt4 key购买 nike

我有一个包含体验的组件,每个体验都有一个弹出窗口。我想为每个弹出窗口显示一组图像。

我有不同的图像数组,如 gastronomiaExperience、deportesExperience、bellezaExperience 等。如何将图像数组添加到弹出窗口

这是我的组件

import React, { memo, useCallback } from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/styles';
import Typography from '@material-ui/core/Typography';
import clsx from 'clsx';
import Popper from '@material-ui/core/Popper';
import gastronomia from 'assets/experiences/gastronomia.jpg';
import productos from 'assets/experiences/productos.jpg';
import giftcard from 'assets/experiences/giftcard.jpg';
import diversion from 'assets/experiences/diversion.jpg';
import deporte from 'assets/experiences/deporte.jpg';
import belleza from 'assets/experiences/belleza.jpg';
import gastronomiaExperiences from 'data/gastronomia';
import productosExperiences from 'data/productos';
import giftcardExperiences from 'data/giftcard';
import diversionExperiences from 'data/diversion';
import deporteExperiences from 'data/deporte';
import bellezaExperiences from 'data/belleza';


// Proptypes definitions to the component.
const propTypes = {
/** Custom root className. */
className: PropTypes.string,

};

// Default props definitions.
const defaultProps = {
className: null,
};

// Component's styles
const useStyles = makeStyles(theme => ({
root: {
display: 'block',
margin: '0 auto',
maxWidth: '50%',
[theme.breakpoints.down('md')]: {
maxWidth: '70%',
},
[theme.breakpoints.down('sm')]: {
maxWidth: '100%',
},
'& .experiences-column': {
display: 'inline-block',
verticalAlign: 'top',
textAlign: 'center',
'&.col1': {
width: '36.31%',
[theme.breakpoints.down('sm')]: {
width: 'initial',
},
},
'&.col2': {
width: '63.69%',
[theme.breakpoints.down('sm')]: {
width: 'initial',
},
},
'& .experience': {
padding: 2,
position: 'relative',
'& img': {
width: '100%',
display: 'block',
},
'& .experience-title': {
position: 'absolute',
bottom: 30,
left: 0,
right: 0,
textAlign: 'center',
},
},
},
},
}), { name: 'ExperiencesStyle' });



/**
* Component used to render a grid of experiences.
*
* @param {object} props - The component's props.
* @returns {object} React element.
*/
const Experiences = memo(
(props) => {
const { className } = props;
const classes = useStyles(props);

const [anchorEl, setAnchorEl] = React.useState(null);


const handleClick = event => {
setAnchorEl(event.currentTarget);
};

const open = Boolean(anchorEl);

const experience = (img, title, category, id, popoverCategory) => (
<div className="experience" aria-describedby={id} id={id} onClick={handleClick} >
<img
data-sizes="auto"
className="lazyload"
data-src={img}
alt={title}
/>
<div className="experience-title">
<Typography
color="textSecondary"
variant="subtitle2"
className="highlight highlight1"
display="inline"
>
{ title }
</Typography>
</div>

<Popper id={id} open={anchorEl && anchorEl.id === id} anchorEl={anchorEl}>
<div className={classes.paper}>
<img
data-sizes="auto"
className="lazyload"
data-src={popoverCategory}
alt="Puntospoint"
/>
</div>
</Popper>
</div>

);


return (
<div className={clsx(classes.root, className)}>
<div className="experiences-column col1">
{experience(gastronomia, 'GASTRONOMÍA', 'gastronomia', 'gastronomia', open, anchorEl, gastronomiaExperiences)}
{experience(giftcard, 'GIFT CARD', 'giftcard','giftcard', open, anchorEl, giftcardExperiences)}
{experience(deporte, 'DEPORTE', 'deporte', 'deporte', open, anchorEl, deporteExperiences)}
</div>
<div className="experiences-column col2">
{experience(productos, 'PRODUCTOS', 'productos', 'productos', open, anchorEl, productosExperiences)}
{experience(diversion, 'DIVERSIÓN', 'diversion', 'diversion', open, anchorEl, diversionExperiences)}
{experience(belleza, 'BELLEZA', 'belleza', 'belleza', open, anchorEl, bellezaExperiences)}
</div>
</div>

);
},
);

// Component proptypes.
Experiences.propTypes = propTypes;

// Component default props.
Experiences.defaultProps = defaultProps;

export default Experiences;

我是 React 和 Material ui 新手

我尝试使用此 img 标签来引入数组,但它只给了我一张图像

        <img
data-sizes="auto"
className="lazyload"
data-src={popoverCategory}
alt="Puntospoint"
/>

最佳答案

我以前没有使用过material ui,但如果我假设popoverCategory在url数组中,你的意思是这样的吗?

<Popper>
<div className={classes.paper}>
{
popoverCatergory.map(url => {
return <img
data-sizes="auto"
className="lazyload"
data-src={popoverCategory}
alt="Puntospoint"
/>
})
}
</div>
</Popper>

关于javascript - 将图像数组添加到弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59682935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com