为什么编译器不能读取从'../addMore/addMore'导入的addMore?
P粉463824410
P粉463824410 2023-08-17 15:20:19
0
1
550
<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粉463824410
P粉463824410

全部回复(1)
P粉358281574

组件名称必须以大写字母开头。将文件名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>
  )
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板