Tom*_*mas 4 javascript laravel reactjs react-material
我使用的是Reactjs在Laravel。在这里我改变了我的阵营组件的一些变化,当我刷新我的浏览器,然后更改都不会显示。
文件:
资源/视图/welcome.blade.php
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>arjunphp.com | Laravel 5.6 with React JS</title>
<link href="{{asset('css/app.css')}}" rel="stylesheet" type="text/css">
</head>
<body>
<div id="example"></div>
<script src="{{asset('js/app.js')}}" ></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)资源/资产/js/app.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes React and other helpers. It's a great starting point while
* building robust, powerful web applications using React + Laravel.
*/
require('./bootstrap');
/**
* Next, we will create a fresh React component instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
require('./components/Example');
Run Code Online (Sandbox Code Playgroud)资源/资产/js/components/Example.js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Button from '@material-ui/core/Button'
export default class Example extends Component {
render() {
return (
<div className="container">
<div className="row">
<div className="col-md-8 col-md-offset-2">
<div className="panel panel-default">
<div className="panel-heading">Example Component</div>
<div className="panel-body">
I'm an example component tomas!
</div>
<Button size="small" color="primary" href="#" target="_blank">
Go To Course
</Button>
</div>
</div>
</div>
</div>
);
}
}
if (document.getElementById('example')) {
ReactDOM.render(<Example />, document.getElementById('example'));
}
Run Code Online (Sandbox Code Playgroud)当我刷新浏览器时,我在此组件中添加了一个 Button 更改未显示在浏览器中。
屏幕截图:
小智 8
如果没有,你是否编译了 react.js 代码:
npm run dev
Run Code Online (Sandbox Code Playgroud)
并清除浏览器缓存以查看更改
Laravel 文档
请记住,每次更改 Vue 组件时都应该运行 npm run dev 命令。或者,您可以运行 npm run watch 命令来监视并在每次修改组件时自动重新编译它们。
也需要做出反应。
试试这个方法,它叫做 Live Reloading。
通过实时重新加载,您可以在保存 .js 文件时刷新浏览器。
转到webbpack.mix.js并在底部添加:
mix.browserSync('localhost:8000');
里面的参数取决于你的 php artisan serve url 和 port。
npm run watch以安装 browserSync 方法所需的依赖项。php artisan serve和npm run watch(在不同的 cmd 上)希望这有帮助。
做对了别忘了鼓掌。
来源:https : //medium.com/@michael.tandio/easy-setup-hot-loader-for-react-laravel-with-laravel-mix-8f68a1393624
| 归档时间: |
|
| 查看次数: |
9608 次 |
| 最近记录: |