我是ReactJS的新手,我想在我的React应用程序中包括引导

我已经通过npm安装bootstrap -save安装了bootstrap

现在,我想在React应用程序中加载引导CSS和JS。

我正在使用webpack。

webpack.config.js

var config = {
    entry: './src/index',

    output: {
        path: './',
        filename: 'index.js'
    },

    devServer: {
        inline: true,
        port: 8080,
        historyApiFallback: true,
        contentBase:'./src'
    },

    module: {
        loaders: [
            {
                test: /\.js?$/,
                exclude: /node_modules/,
                loader: 'babel',

                query: {
                    presets: ['es2015', 'react']
               }
            }
        ]
    }
};

module. exports = config;

我的问题是“如何从节点模块中包含引导CSS和JS在ReactJS应用程序中?”如何设置引导包括在我的React应用程序?


当前回答

下面是我用npm的bootstrap 4所做的工作

安装jquery, popper.js, bootstrap包 NPM安装jquery popper.js bootstrap—save 使用以下导入更新index.js 导入“引导/ dist / css / bootstrap.min.css”; 导入“引导/ dist / js / bootstrap.js”;

此外,如果您使用sass自定义样式,您可以安装sass包

npm install sass --save

其他回答

希望这是有帮助的;)

第一步:使用NPM安装以下命令

npm install --save reactstrap@next react react-dom

步骤2:示例index.js主脚本导入bellow命令

import 'bootstrap/dist/css/bootstrap.min.css';

步骤3:UI组件参考以下网站 reactstrap.github.io

如果你在项目中使用CRA(create-react-app),你可以添加这个:

npm install react-bootstrap bootstrap

如果你在你的应用中使用bootstrap,如果它不起作用,那么在index.html中使用这个:

<link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
  integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
  crossorigin="anonymous"
/>

我用上面的方法来解决类似的问题。希望这对你有用:-)

我尝试指导:

npm install bootstrap
npm install jquery popper.js

然后在src/index.js中:

import 'bootstrap/dist/css/bootstrap.min.css';
import $ from 'jquery';
import Popper from 'popper.js';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<Dropdown />, document.getElementById('root'));
registerServiceWorker();

这里是如何包括最新的引导 https://react-bootstrap.github.io/getting-started/introduction

1.安装

NPM安装react-bootstrap

然后导入到App.js 导入“引导/ dist / css / bootstrap.min.css”; 然后你需要导入你在应用程序中使用的组件,例如 如果你使用导航条,导航,按钮,表单,表单控件,然后导入所有这些如下所示:

import Navbar from 'react-bootstrap/Navbar'
import Nav from 'react-bootstrap/Nav'
import Form from 'react-bootstrap/Form'
import FormControl from 'react-bootstrap/FormControl'
import Button from 'react-bootstrap/Button'


// or less ideally
import { Button } from 'react-bootstrap';

因为Bootstrap/Reactstrap已经发布了他们的最新版本,即Bootstrap 4,你可以按照以下步骤使用它

导航到您的项目 打开终端 我假设已经安装了npm,然后输入以下命令 NPM install——save react-dom

这将在您的项目中作为依赖项安装Reactstrap。

下面是使用react创建按钮的代码

import React from import {Button} from 'reactstrap'; 导出默认值(props) => { 回报( <按钮颜色= "危险" >危险!< / >按钮 ); };

你可以通过访问他们的官方页面来检查Reactstrap