Image on Material UI CardMedia

后端 未结 5 1608
别那么骄傲
别那么骄傲 2020-12-28 23:19

I´m having some troubles on getting an image from props on a CardMedia image:


    

        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-28 23:47

    I was facing the same issue. A good workaround would be to use the 'img' element along with the 'src' attribute inside the CardMedia body instead of passing it as an attribute to the CardMedia.

    
     recipe thumbnail
    
    

    And while passing the props to the class I sent the image path as an object. In your case, suppose recipe is an object with thumbnail as one of the attributes. Then in the parent class, I would write the prop as:

    ...
    recipe = {
      .
      .
      thumbnail: require('assets/images/img1.jpg'),
      //make sure the path of the image is relative to parent class where you are defining the prop 
      .
      .
    }
    ...
    

    Here I am sending the path of the image as an object. This worked for me.

提交回复
热议问题