mimicreative/yii2-react

Yii2 的 ReactJS 资产包

安装次数: 359

依赖项: 0

建议者: 0

安全: 0

星标: 13

关注者: 5

分支: 11

公开问题: 0

类型:yii2-extension

1.0.2 2016-10-18 08:26 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:04:12 UTC


README

安装

安装此扩展的首选方式是通过 Composer

将以下内容添加到你的 composer.json 文件的 require 部分

"mimicreative/yii2-react": "~1.0"

然后在终端中运行

composer update

用法

在 Yii2 视图文件中将它用作资产包。

// use this if you do not need addons
\mimicreative\react\ReactAsset::register($this);

// use this if you need addons
\mimicreative\react\ReactWithAddonsAsset::register($this);

默认情况下,此扩展使用压缩版本。我还包括了 react-dom.min.js,因为我们通常需要它来在 JS 文件中渲染。要自定义要使用的资产,你可以在 Yii2 配置文件中设置配置。请参阅 React Bower 包 了解文件列表。

例如,如果你想使用非压缩版本

// in main.php config file

return [
  'components' => [
    'assetManager' => [
      'bundles' => [
        'mimicreative\react\ReactAsset' => [
          'js' => [
            'react.js',
            'react-dom.js'
          ]
        ],
        'mimicreative\react\ReactWithAddonsAsset' => [
          'js' => [
            'react-with-addons.js',
            'react-dom.js'
          ]
        ]
      ]
    ]
  ]
];

更多信息

请参阅 React.js 网站 的文档以获取有关其配置选项的更多信息。