[英]How can I run ReactJs with Laravel
I tried to installLlaravel and scaffold ReactJs.我尝试安装 Llaravel 和脚手架 ReactJs。
I have a problem in running my react component.我在运行 React 组件时遇到问题。
The installation was fine and Below is my first ReactJs component.安装很好,下面是我的第一个 ReactJs 组件。 However I cannot display the content of the react component.但是我无法显示反应组件的内容。
components/Example.js组件/Example.js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
export default class Example extends Component {
render() {
return (
<div className="container">
<div className="row justify-content-center">
<div className="col-md-8">
<div className="card">
<div className="card-header">Example Component</div>
<div className="card-body">I'm an example component!</div>
</div>
</div>
</div>
</div>
);
}
}
if (document.getElementById('example')) {
ReactDOM.render(<Example />, document.getElementById('example'));
}
Here is the file welcome.blade, inside the body这是文件welcome.blade,在body里面
<div id="example"></div>
<script src="/js/app.js"></script>
It should display like this,它应该像这样显示,
Example Component示例组件
I'm an example component!我是一个示例组件!
npm run dev
for development and npm run prod
for production on your laravel root directory在 Laravel 根目录中运行npm run dev
进行开发, npm run prod
进行生产
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.