React Bootstrap table not formatting
我是一个非常新的反应者,正在尝试遵循基本的表格教程。
我已经安装了react-bootstrap-table
1 | npm install react-bootstrap-table --save |
我已经导入了引导表
1 | import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table'; |
我已经导入了css文件:
1 | import '../../node_modules/react-bootstrap-table/dist/react-bootstrap-table-all.min.css'; |
有了上述内容,我希望表格显示如下:
但是我在代码中看到的是:
为什么表格没有如示例中所示?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | import React, { Component } from"react"; import './MenuButton.css'; import './MenuContainer.css'; import MenuButton from './MenuButton'; import Menu from './Menu'; import serverCall from"../api/ServerCall"; import {BootstrapTable,TableHeaderColumn} from 'react-bootstrap-table'; import '../../node_modules/react-bootstrap-table/css/react-bootstrap-table.css' class MenuContainer extends Component { constructor(props, context) { super(props, context); this.state = { visible: false }; this.handleMouseDown = this.handleMouseDown.bind(this); this.toggleMenu = this.toggleMenu.bind(this); this.getCustomers(); } handleMouseDown(e) { this.toggleMenu(); e.stopPropagation(); } toggleMenu() { this.setState({ visible: !this.state.visible }); } getCustomers(){ console.log("Getting Customers"); serverCall(function(error, response) { if (error) { alert("Authorization Failed.") } else { console.log(response); } },"","customers.php"); } render() { let products = [{ id: 1, name:"Item name 1", price: 100 },{ id: 2, name:"Item name 2", price: 100 }]; return ( <MenuButton handleMouseDown={this.handleMouseDown}/> <Menu handleMouseDown={this.handleMouseDown} menuVisibility={this.state.visible}/> Dashboard | Customers <BootstrapTable data={ products }> <TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn> <TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn> <TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn> </BootstrapTable> ); } } export default MenuContainer; |
供以后参考,您只需要从应用程序的基础而不是node_modules路径导入。我使用以下内容,并且工作正常:
尝试此行
导入\\'../../ node_modules / react-bootstrap-table / css / react-bootstrap-table.css \\'
在主要入口组件中