使用React Bootstrap搭建网页界面

先安装node,如果有旧版本的node需要先卸载

bash 复制代码
sudo apt-get remove nodejs
sudo apt-get autoremove

安装node,官网为https://deb.nodesource.com/

按照提示安装最新版

快速搭建 Vite 项目的命令,xxx为项目名

bash 复制代码
npm create vite xxx

安装react-bootstrap

bash 复制代码
npm install react-bootstrap bootstra

要想使用bootstrap需要修改以下文件

  1. 删除app.css与index.css,将app.jsx中的import './App.css'删除

  2. 将main.jsx中的import App from './App.jsx'与import './App.css'删除,再添加 import "bootstrap/dist/css/bootstrap.css"

  3. 再创建components文件夹存放自己写的代码

可以参考react-bootstrap官网的示例

https://react-bootstrap.github.io/docs/getting-started/introduction

在components中创建mainpage.jsx文件

添加react-bootstrap官网中的一个小例子

bash 复制代码
import Alert from 'react-bootstrap/Alert';

function BasicExample() {
  return (
    <>
      {[
        'primary',
        'secondary',
        'success',
        'danger',
        'warning',
        'info',
        'light',
        'dark',
      ].map((variant) => (
        <Alert key={variant} variant={variant}>
          This is a {variant} alert---check it out!
        </Alert>
      ))}
    </>
  );
}

export default BasicExample;

修改App.jsx的内容

bash 复制代码
import { useState } from 'react'

import BasicExample from './components/mainPage'

function App() {
  const [count, setCount] = useState(0)

  return (
    <>

      <BasicExample />

    </>
  )
}

export default App

然后运行代码

bash 复制代码
npm run dev

点击local链接,跳转到浏览器,查看效果

如果设计好页面后可以直接构建出生产环境代码

bash 复制代码
npm run build
相关推荐
子兮曰5 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰5 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
前端小万5 天前
写公众号赚了 3000 块后,我做了一款叫 "一键成稿" 的软件
前端·微信小程序
爱勇宝5 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
三十而立洋5 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
卡布鲁5 天前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
汉堡大王95275 天前
Jev:不是聊天机器人, 而是一个智能 if 语句
前端·人工智能·后端
梦想很大很大5 天前
从运行事实到回归证据:Workrun 的 Telemetry 与 Evaluation 实践
前端·人工智能·后端
计算机魔术师5 天前
Meta Muse agent 接入 Shopify 的 Shop Pay 实现代理式购物
前端
沙蒿同学5 天前
我用 Go 搭了一条 AI Agent 流水线:从 1 张商品图到一整套淘宝详情页
前端·javascript·后端