私信发送成功
检测到您已登录开源中国,是否 一键登录码云
Watch Star Fork

oyhk / mkfree-blogNodeJS

模板引擎更换react
oyhk 提交于   master
commit eac1fa6109bc278143c14408f502491ecca2918e
1 parent d2d33302f2

6 文件发生了变化, 影响行数: +51 -2

@@ -13,7 +13,9 @@ var app = express();
 
// view engine setup
app.set('views', path.join(__dirname, 'views'));
-app.set('view engine', 'jade');
+// app.set('view engine', 'jade');
+app.set('view engine', 'jsx');
+app.engine('jsx', require('express-react-views').createEngine());
app.locals.env = process.env;
 
// uncomment after placing your favicon in /public
@@ -6,7 +6,7 @@ class PageResult {
constructor(pageNo, pageSize) {
this.pageSize = parseInt(pageSize);
this.pageNo = parseInt(pageNo);
- this.offset = (this.pageNo-1) * this.pageSize
+ this.offset = (this.pageNo - 1) * this.pageSize
}
 
init(total, data, url) {
@@ -11,10 +11,13 @@
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
+ "express-react-views": "^0.10.2",
"jade": "~1.11.0",
"morgan": "~1.7.0",
"mysql": "^2.11.1",
"node-sass-middleware": "0.8.0",
+ "react": "^15.3.2",
+ "react-dom": "^15.3.2",
"serve-favicon": "~2.3.0"
}
}
@@ -0,0 +1,15 @@
+var React = require('react');
+var DefaultLayout = require('./layout');
+
+class Error extends React.Component {
+ render() {
+ return (
+ <DefaultLayout title={this.props.message}>
+ <div>{this.props.error.status}</div>
+ <div>{this.props.error.stack}</div>
+ </DefaultLayout>
+ );
+ }
+}
+
+module.exports = Error;
\ No newline at end of file
@@ -0,0 +1,14 @@
+var React = require('react');
+var DefaultLayout = require('./layout');
+
+class Index extends React.Component {
+ render() {
+ return (
+ <DefaultLayout title={this.props.title}>
+ <div>Hello {this.props.name}</div>
+ </DefaultLayout>
+ );
+ }
+}
+
+module.exports = Index;
\ No newline at end of file
@@ -0,0 +1,15 @@
+var React = require('react');
+
+class DefaultLayout extends React.Component {
+ render() {
+ return (
+ <html>
+ <head><title>{this.props.title}</title></head>
+ <body>{this.props.children}</body>
+ <script type="text/javascript" src="/plugin/jQuery/jquery-2.2.3.min.js"></script>
+ </html>
+ );
+ }
+}
+
+module.exports = DefaultLayout;
\ No newline at end of file

登录 后才可以发表评论