小编Wyo*_*key的帖子

映射Material-UI卡时未加载图像

我有点不适应,这是第一次尝试从API调用中获取信息,通过它进行映射,并为每个响应制作一个Material-UI卡。当我制作一张卡时,它就很好了。当我映射响应时,将为每个响应制作卡片,并将文本正确输入到字段中,但不会加载图像。即使使用未从响应加载的静态图像,该图像也不会显示。这是我正在查看的内容:

//调用API,映射结果并构建卡

import React, {Component} from 'react'


import Request from 'superagent'
import Grid from '@material-ui/core/Grid'
import Cards from './cards'


const url = "http://localhost:4000/products"
const get = Request.get(url)

class ProductList extends Component {
    state = {
        products: []

    }

    constructor() {
        super()
        this.getProducts()
    }

    getProducts = () =>

    Request.get(url)
    .then((response) => {
        const prods = (response.body.products)
        console.log(prods)
        this.setState({products: prods})
    })

render() {
    return (
    <div>
        {this.state.products ? (

            <Grid container spacing={24} style = {{padding: 24}}>
            { this.state.products.map(prods => (
                <Grid item …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

3
推荐指数
3
解决办法
2869
查看次数

标签 统计

material-ui ×1

reactjs ×1