1奖蔓、用webstorm打sails項(xiàng)目,在當(dāng)前項(xiàng)目目錄下執(zhí)行下面命令衔蹲,安裝express-react-views必要組件:
npm install express-react-views react react-dom
2、安裝必要組件后,配置sails視圖引擎注服,打開config/views.js添加如下代碼:
extension: 'jsx',
getRenderFn: function () {
? return require('express-react-views').createEngine();
}
3、創(chuàng)建一個(gè)測(cè)試控制器TestController(或執(zhí)行g(shù)enerate new controller test)措近,代碼如下:
module.exports = {
? test: function (req,res) {
? ? return res.view('hello',{ name: "kimi" });
? }
};
4溶弟、創(chuàng)建一個(gè)hello視圖,代碼如下:
var React = require('react');
class HelloMessage extends React.Component {
?render() {?
?return Hello {this.props.name};?
?}
}
module.exports = HelloMessage;
5瞭郑、配置policies和routers的信息辜御,如下:
// policies.js
'test/test': true?
// routers.js
'GET /test': { action: 'test/test'? }
6、啟動(dòng)項(xiàng)目屈张,打開瀏覽器查看效果擒权,如下圖: