我是 Reactjs 的新手,正在嘗試開發(fā)靜態(tài)網(wǎng)站。到目前為止,能夠渲染像 carasouel 和卡片這樣的少數(shù)組件。然而,在最近的發(fā)展中,具體<div>的被渲染了兩次。在進行故障排除時,我看到它<div>來了兩次,但在代碼中,只寫<div>了一次。撓頭如何解決這個問題。這是代碼:App.jsimport React, { Fragment, Component } from "react";import { BrowserRouter as Router, Route } from "react-router-dom";import { Button } from "react-bootstrap";import Carasel from "./Components/carosel";import Cards from "./Components/cards";class App extends Component { render() { return ( <Router> <Carasel /> <Cards /> </Router> ); }}export default App;index.jsimport React from "react";import ReactDOM from "react-dom";import App from "./App";const rootElement = document.getElementById("root");ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>, rootElement);卡片.jsimport React, { Component } from "react";import img1 from "../test/person1.jpg";import "bootstrap/dist/css/bootstrap.min.css";import { Button } from "react-bootstrap";import "./card-style.css";class Card extends Component { render() { const mouse = this.props.mouse; return ( <div className="card text-center"> <div className="overflow"> <img src={img1} alt="image1" /> </div> <div className="card-body text-dark" /> <h4 className="card-title">{mouse}</h4> <p className="card-text text-secondary">lorem20</p> <a href="#" className="btn btn-outline-success"> Go Anywhere </a> </div> ); }}export default Card;現(xiàn)在的問題是:<div className="card text-center">最后被渲染了兩次。沒有得到問題所在。在進行故障排除時,組件似乎是有狀態(tài)的?請建議
React 組件被渲染兩次
天涯盡頭無女友
2022-10-13 15:43:00