【发布时间】:2019-04-24 19:07:36
【问题描述】:
我在 Laravel 中使用 Reactjs。这里我对我的 React 组件进行了一些更改,当我刷新浏览器时,更改不会显示。
文件:
-
资源/视图/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> -
资源/资产/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'); -
resources/asset/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')); }
我在刷新浏览器时在此组件中添加了一个按钮,更改未显示在浏览器中。
屏幕截图:
【问题讨论】:
-
可能(取决于您的设置)您必须先运行“npm run dev”才能看到任何更改……可能(取决于您的设置)您会在包中找到可用的 npm 命令。 json文件
-
在开始开发后使用
npm run watch --watch-poll命令,NPM 将在任何更改后即时侦听并重新构建所有 JS 组件。 -
请问你是怎么解决这个问题的?我有类似的问题。
标签: javascript reactjs laravel react-material