gpt4 book ai didi

javascript - 必须包裹在封闭标签中

转载 作者:行者123 更新时间:2023-11-30 07:07:23 25 4
gpt4 key购买 nike

我在创建一个在我的 React 应用程序中呈现菜单的简单组件时遇到了问题。

这是我的组件的代码:

import React, { Component } from 'react';

export default class menu extends Component {

render() {
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<a className="navbar-brand" href="#">Navbar</a>
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNavDropdown">
<ul className="navbar-nav">
<li className="nav-item active">
<a className="nav-link" href="#">Home <span className="sr-only">(current)</span></a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Features</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Pricing</a>
</li>
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div className="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a className="dropdown-item" href="#">Action</a>
<a className="dropdown-item" href="#">Another action</a>
<a className="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
);
}

}

我将它放在另一个组件中。

import menu from './componentes/menu';

构造函数( Prop ){ super ( Prop ) this.state = { sistemas: [] };

class App extends Component {

render() {
return (
<div>
<menu></menu>
</div>
<div className="App">

<div className="bs-header" id="content">
<div className="container">
<h1>Template Changelog</h1>
<p>Lists all changes to the HTML template files</p>
</div>
</div>

); //[js] JSX expressions must have one parent element.
}

}

我还在注释行中收到以下错误

[js] JSX 表达式必须有一个父元素。

最佳答案

您的 App 有不止一个顶级 div。将两者都包装在另一个 div 中。

关于javascript - 必须包裹在封闭标签中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49743547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com