在laravel中使用React好像有点那啥,但是这样可以学到React的知识也能学到Laravel的知识何乐而不为?因为自己之前在大二寒假时候学习过React距离现在都不知过了多久了,也一直没用过,现在都望光了估计,那么现在来重新计划一下吧.
当我安装完之后,发现整个项目100多M!!!不过也正常似乎,因为有node_models的存在
1.你安装了一个Laravel项目,我安装的是Laravel8
2.安装laravel/ui
composer require laravel/ui --devCopy
此处参考了:请问 Laravel 7 是不是移除了 artisan preset 命令?
3.php artisan ui react
php artisan ui vue也是安装vue的方法;这里是安装reactjs.网上说这个命令是修改前端预置,但我也不太了解
//安装好,控制台提示安装成功
React scaffolding installed successfully.
Please run "npm install && npm run dev" to compile your fresh scaffolding.
4.npm安装
此过程约10分钟左右(我的网络太差了可能)
npm install
到这一步尝试执行一下npm run dev,如果显示如下错误:
> npm run development> @ development F:\project\xxx> mix Additional dependencies must be installed. This will only take a moment. Running: npm install resolve-url-loader@^5.0.0 --save-dev --legacy-peer-deps Finished. Please run Mix again.npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! @ development: `mix`npm ERR! Exit status 1npm ERR!npm ERR! Failed at the @ development script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR! E:\xxx\node_cache\_logs\2022-07-10T15_33_39_792Z-debug.lognpm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! @ dev: `npm run development`npm ERR! Exit status 1npm ERR!npm ERR! Failed at the @ dev script.npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:npm ERR! E:\xxx\node_cache\_logs\2022-07-10T15_33_39_960Z-debug.log
那么根据提示还需要安装其它依赖:npm install resolve-url-loader@^5.0.0 –save-dev –legacy-peer-deps
安装完成再次npm run dev,成功运行!