当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

react-laravel

Package for using ReactJS with Laravel
授权协议 Readme
开发语言 PHP
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 胡弘毅
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

react-laravel

With react-laravel you'll be able to use ReactJS components right from your Blade views, with optional server-side rendering, and use them on the client-side with React due to unobtrusive JavaScript.

Installation

V8js dependency

It's important to know that react-laravel has an indirect dependency of the v8js PHP extension.

You can see how to install it here: how to install v8js.

Composer

Set the minimum-stability of your composer.json to dev, adding this:

"minimum-stability": "dev"

Then run:

$ composer require talyssonoc/react-laravel:0.11

After that you should add this to your providers at the config/app.php file of your Laravel app:

'React\ReactServiceProvider'

And then run:

php artisan vendor:publish

And the react.php file will be available at the config folder of your app.

Usage

After the installation and configuration, you'll be able to use the @react_component directive in your views.

The @react_component directive accepts 3 arguments:

@react_component(<componentName>[, props, options])

  //example
  @react_component('Message', [ 'title' => 'Hello, World' ], [ 'prerender' => true ])

  // example using namespaced component
  @react_component('Acme.Message', [ 'title' => 'Hello, World' ], [ 'prerender' => true ])
  • componentName: Is the name of the global variable that holds your component. When using Namespaced Components you may use dot-notation for the component name.
  • props: Associative of the props that'll be passed to your component
  • options: Associative array of options that you can pass to the react-laravel:
    • prerender: Tells react-laravel to render your component server-side, and then just mount it on the client-side. Default to true.
    • tag: The tag of the element that'll hold your component. Default to 'div'.
    • html attributes: Any other valid HTML attribute that will be added to the wrapper element of your component. Example: 'id' => 'my_component'.

All your components should be inside public/js/components.js (you can configure it, see below) and be global.

You must include react.js, react-dom.js and react_ujs.js (in this order) in your view. You can concatenate these files together using laravel-elixir.

react-laravel provides a ReactJS installation and the react_us.js file, they'll be at public/vendor/react-laravel folder after you install react-laravel and run:

$ php artisan vendor:publish --force

For using the files provided by react-laravel and your components.js file, add this to your view:

<script src="{{ asset('vendor/react-laravel/react.js') }}"></script>
  <script src="{{ asset('vendor/react-laravel/react-dom.js') }}"></script>
  <script src="{{ asset('js/components.js') }}"></script>
  <script src="{{ asset('vendor/react-laravel/react_ujs.js') }}"></script>

If you'll use a different version from the one provided by react-laravel (see composer.json), you got to configure it (see below).

Configurations

You can change settings to react-laravel at the config/react.php file:

return [
    'source' => 'path_for_react.js',
    'dom-source' => 'path_for_react-dom.js',
    'dom-server-source' => 'path_for_react-dom-server.js',
    'components' => [ 'path_for_file_containing_your_components.js' ]
  ];

All of them are optional.

  • source: defaults to public/vendor/react-laravel/react.js.
  • dom-source: defaults to public/vendor/react-laravel/react-dom.js.
  • dom-server-source: defaults to public/vendor/react-laravel/react-dom-server.js.
  • components: defaults to public/js/components.js. Multiple components files may be specified here.

Your components.js file(s) should also be included at your view, and all your components must be at the window object.

Thanks

This package is inspired at react-rails.

  • MrCoder技术栈博客 20190124开源声明 总花费大约一周时间,陆陆续续开发,laravel+react+next主题的博客系统日渐丰满,是时候分享成果了。喜欢的请star一下。系统会持续更新。 DEMO: GIT: Gitee: 背景 博主一直使用git page + hexo搭建个人的博客,奈何,渐渐发现了问题 seo差的几乎没有 访问速度慢的掉渣 于是本着不重复造轮子的前提下,git

 相关资料
  • 问题内容: 我注意到可以这样导入: …或像这样: 第一个导入模块中的所有内容(请参阅:导入整个模块的内容) 第二个仅导入模块导出(请参阅:导入默认值) 似乎这两种方法是不同的,并且根本上是不兼容的。 为什么它们都起作用? 请参考源代码并解释该机制…我有兴趣了解其工作原理。 ES6常规模块信息回答了该问题。 我在问使模块像这样工作的机制。在这里,它似乎与源代码中的 “ hacky”导出机制有关,但尚

  • 这篇快速上手指南会教你如何将TypeScript与React结合起来使用。 在最后,你将学到: 使用TypeScript和React创建工程 使用TSLint进行代码检查 使用Jest和Enzyme进行测试,以及 使用Redux管理状态 我们会使用create-react-app工具快速搭建工程环境。 这里假设你已经在使用Node.js和npm。 并且已经了解了React的基础知识。 我们之所以使

  • 我已经改用react Native制作跨平台应用程序(虽然没有制作)。我只是想要一个答案,我的问题,反应和反应之间的区别。我在网上搜索了一下,但没有找到合适的答案。

  • 问题内容: 与 哪个更好,为什么? 还是除了以后编写更少的代码外没有其他区别? 写作是否意味着只导入Component对象? 问题答案: 让您代替。它减少了React名称空间的键入和重复,这通常是一种理想的现代编码约定。 此外,Webpack 2和Rollup之类的工具会“摇晃”,这意味着任何未使用的导出都不会捆绑到您的最终代码中。使用/,您可以保证所有React的源代码都将被捆绑。使用,某些工具

  • 本文向大家介绍react-native 启动React Native Packager,包括了react-native 启动React Native Packager的使用技巧和注意事项,需要的朋友参考一下 示例 在最新版本的React Native上,无需运行打包程序。它将自动运行。 默认情况下,这将在端口8081上启动服务器。要指定服务器所在的端口            

  • 我正在使用“React admin”创建一个管理界面(前端)。我正在使用spring boot作为我的REST API。我的React应用程序的url是:“http://localhost:3000”。我的spring boot API的url是:“http://localhost:8080”。 下面是CORS配置的spring boot代码,它在一个单独的类中,称为CORSCONFIG: 下面是

  • 主要内容:React 实例React 支持一种非常特殊的属性 Ref ,你可以用来绑定到 render() 输出的任何组件上。 这个特殊的属性允许你引用 render() 返回的相应的支撑实例( backing instance )。这样就可以确保在任何时间总是拿到正确的实例。 使用方法 绑定一个 ref 属性到 render 的返回值上: 在其它代码中,通过 this.refs 获取支撑实例: 完整实例 你可以通过使用

  • 主要内容:React 实例React 组件的数据可以通过 componentDidMount 方法中的 Ajax 来获取,当从服务端获取数据时可以将数据存储在 state 中,再用 this.setState 方法重新渲染 UI。 当使用异步加载数据时,在组件卸载前使用 componentWillUnmount 来取消未完成的请求。 以下实例演示了获取 Github 用户最新 gist 共享描述: React 实例 cla