Javascript 如何使react加载引导类,className="&引用;

Javascript 如何使react加载引导类,className="&引用;,javascript,css,reactjs,bootstrap-4,Javascript,Css,Reactjs,Bootstrap 4,我在我的机器上安装了bootstrap并创建了带有npm的react应用程序。然后,我使用第一个组件counter.jsx创建了一个新的react应用程序: import React, { Component } from 'react'; class Counter extends Component { state = { name: test }; render() { return ( <div> <s

我在我的机器上安装了bootstrap并创建了带有npm的react应用程序。然后,我使用第一个组件counter.jsx创建了一个新的react应用程序:

import React, { Component } from 'react';
 class Counter extends Component {    
  state = {    
    name: test    
  };   
render() {  
 return ( 
  <div>
    <span> className="badge badge-primary">{this.state.name)}</span>    
    <button>Increment</button>    
  </div>
 );
}

export default Counter;

我用谷歌搜索了这个问题,并尝试配置我的webpack.config.js。这没什么帮助,但我不确定我是否做了正确的改变。你们中有人以前遇到过同样的问题吗?

您的
span
标签上有一个打字错误(您关闭了两次)

替换:
className=“badge badge primary”>

作者:


另外,您正在关闭一个
,就在
this.state.name
之前没有打开的人之后,请确保您想要它

替换:
{this.state.name)}

作者:
{this.state.name}


已更新

好的,您还有其他问题,这里是最终版本,包含所有修复:

我改变了什么:

  • 为了关闭组件(在关闭render()函数之后),您忘记了最后一个
    }
  • test
    变量不存在,因此我将
    name:test
    替换为
    name:'test'

它现在运行良好=]

我已修复了打字错误,但问题仍然存在,请修复其他问题非常感谢。现在可以了,我觉得有点傻。为什么要更新你的问题来解决你的问题?现在你的问题对未来的读者没有任何意义。
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import 'bootstrap/dist/css/bootstrap.css';
import Counter from './components/counter';

ReactDOM.render(
 <React.StrictMode>
  <Counter />
 </React.StrictMode>,
 document.getElementById('root')
);