bootstrap模态在React中不起作用。有人可以帮我吗?

问题描述 投票:0回答:1
当我单击启动演示模式按钮时,模式未显示。我已经在节点JS中安装了引导程序,并将其导入index.js。我不知道为什么不起作用。

import React, { useState, useEffect } from "react"; import axios from "axios"; function FetchLists() { const [data, setData] = useState([]); const fetch = async () => { try { const getData = await axios.get( "http://localhost:5000/cinephile/lists/fetch", { headers: { "auth-token": localStorage.getItem("auth-token"), }, } ); setData(getData.data); } catch (error) { console.log(error); } }; useEffect(() => { fetch(); }, [data]); return ( <> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal"> Launch demo modal </button> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h1 class="modal-title fs-5" id="exampleModalLabel">Modal title</h1> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div> </> ); } export default FetchLists;

当我单击启动演示模式按钮时,模式未显示。我已经在节点JS中安装了引导程序,并将其导入index.js。我不知道为什么不起作用。有人可以帮我解决这个问题吗?
    

确保您在index.js
reactjs bootstrap-modal bootstrap-5
1个回答
0
投票
Bootstrap CSS

Bootstrap JS
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';

但是当您使用React时,我建议您使用React-Bootstrap中的
Modal
。 在这里,您可以找到它的详细信息:

回答bootstrapmodal


    
	

© www.soinside.com 2019 - 2025. All rights reserved.