【发布时间】:2021-08-22 23:43:56
【问题描述】:
使用npm install bootstrap 安装引导程序后,我将样式添加到/pages/_app.js,如下所示:
import 'bootstrap/dist/css/bootstrap.css';
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
但是,使用 javascript 的任何内容都无法正常工作,例如Collapse example 来自他们的文档。
function App() {
return (
<div>
<p>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-bs-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
</div>
);
}
export default App
如果我将import 'bootstrap/dist/js/bootstrap.js' 添加到/pages/_app.js,那么它会按预期开始“工作”,直到重新加载显示ReferenceError: document is not defined(screenshot) 的页面,这让我相信这是不可能的,或者我不应该这样做不要尝试使用 boostrap + react 或 next.js。
我原以为他们放弃 jquery 意味着它应该与 react 之类的框架一起“开箱即用”(因为不再需要 react-boostrap 或 reactstrap)
有没有办法正确使用 boostrap 5 和 nextjs?或者我应该完全尝试其他方法还是重新使用 reactstrap(目前似乎只支持 boostrap 4)?
【问题讨论】:
-
是的,你绝对可以使用来自 Angular、Next 和 ReactJS 的 Bootstrap 5。不,它与“放弃 jQuery”无关(尽管我碰巧喜欢 jQuery!)在这里寻找几种解决方案:stackoverflow.com/a/65260998/421195。请发回对您有用的内容!
-
@paulsm4 感谢您的回复,我认为不可能使用的思路来自于看到多个帖子说使用引导程序和反应是愚蠢的,而您应该使用材料 ui。但是因为我知道引导程序,所以如果可能的话,我想尝试使用它。至于你链接的问题,这些都对我不起作用。我仍然得到“文档未定义”,或者如果我使用最佳答案,我得到“窗口未定义”
标签: javascript node.js reactjs next.js bootstrap-5