搜索

首页  >  问答  >  正文

为什么编译器不能读取从'../addMore/addMore'导入的addMore?

<p>我想要添加一个组件 'addMore',但是编译器不识别它。我漏掉了什么?请帮忙。</p> <p><br /></p> <pre class="brush:js;toolbar:false;">import React from 'react' import { MdDeleteForever } from 'react-icons/md' import addMore from '../addMore/addMore' import './ShoppingCardItem.css' export default function ShoppingCardItem() { return ( <div className='shoppingCardItem-Container'> <img src="./img/Apfel.jpg" alt="" /> <p>2x Apfel</p> <addMore /> <MdDeleteForever /> </div> ) }</pre> <p><br /></p> <p><br /></p> <pre class="brush:js;toolbar:false;">import React from 'react' export default function addMore() { return ( <div className="btn-group"> <button type="button" className="btn btn-primary">+</button> <button type="button" className="btn btn-primary">-</button> </div> ) }</pre> <p><br /></p>
P粉463824410P粉463824410466 天前540

全部回复(1)我来回复

  • P粉358281574

    P粉3582815742023-08-18 09:40:32

    组件名称必须以大写字母开头。将文件名addMore.jsx重命名为AddMore.jsx,并且还要更改导入路径。查看此信息请访问React.dev功能组件

    // ShoppingCardItem.jsx
    
    import React from 'react'
    import { MdDeleteForever } from 'react-icons/md'
    import AddMorefrom '../AddMore/AddMore'
    import './ShoppingCardItem.css'
    
    
    export default function ShoppingCardItem() {
    
      return (
        <div className='shoppingCardItem-Container'>
            <img src="./img/Apfel.jpg" alt="" />
            <p>2x Apfel</p>
            <AddMore/>
            <MdDeleteForever />
            
        </div>
      )
    }
    // AddMore.jsx
    
    import React from 'react'
    
    export default function AddMore() {
      return (
        <div className="btn-group">
            <button type="button" className="btn btn-primary">+</button>
            <button type="button" className="btn btn-primary">-</button>
        </div>
      )
    }

    回复
    0
  • 取消回复