【问题标题】:Prints in console, but not in on page?在控制台中打印,但不在页面中?
【发布时间】:2020-10-10 02:11:19
【问题描述】:

谁能在这里发现问题?

import React from 'react'

export default function CoinTable(props){
    props.data.map(row=> {
        console.log(row.first_name)
    })

    return (
        <table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Subscription</th>
                </tr>
            </thead>
            <tbody>
                {
                    props.data.map(row => {
                        <tr>
                            <td>{row.first_name} {row.last_name}</td>                     
                            <td>{row.phone}</td> 
                            <td>{row.email}</td>                                           
                        </tr>
                    })
                }
            </tbody>
        </table>
    )
}

由于某种原因,代码出现在控制台上,但没有出现在屏幕上。如果有帮助,我也会从 JSON 文件中打印。

【问题讨论】:

  • 在第二张地图中,如果你把console.log(row)放在控制台上会打印什么?
  • 你能显示你为data赋值的代码吗?

标签: html next.js tailwind-css


【解决方案1】:

您不会返回 map 中的 DOM。

props.data.map(row => {
    return (
       <tr>
         <td>{row.first_name} {row.last_name}</td>                     
         <td>{row.phone}</td> 
         <td>{row.email}</td>                                           
      </tr>
    )
})

或者准确地说:

props.data.map(row => (
       <tr>
         <td>{row.first_name} {row.last_name}</td>                     
         <td>{row.phone}</td> 
         <td>{row.email}</td>                                           
      </tr>
))

【讨论】:

  • 哦,谢谢。我会在星期一的工作中尝试这些。我对 NextJS 有点陌生,所以是的。
猜你喜欢
  • 2023-03-22
  • 2020-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
  • 1970-01-01
  • 1970-01-01
  • 2023-01-21
相关资源
最近更新 更多