我已经在其他框架(如Django和Ruby on Rails)中开发了反应,并且最近尝试使用Node.js进行开发。但是,我无法在输入框中触发onChange事件,下面是我正在使用的代码。
server.js
let express = require('express');
let app = express();
let routes = require('./routes/index');
app.use('/',routes);
app.set('port', process.env.PORT || 8000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jsx');
app.engine('jsx', require('express-react-views').createEngine());
app.use("/public/styles", express.static(__dirname + '/public/styles'));
app.use("/public/js", express.static(__dirname + '/public/js'));
app.use("/public/fonts", express.static(__dirname + '/public/fonts'));
app.use("/public/font", express.static(__dirname + '/public/font'));
let server = app.listen(app.get('port'), () =>{
console.log("App is running.");
});
路由/ index.js
let express = require('express');
let router = express.Router();
router.get('/', (req, res) =>{
res.render('index',{});
})
module.exports = router;
视图/ index.jsx
let React = require('react');
let ReactDOM = require('react-dom');
let DefaultLayout = require('./layout/master').default
export default class Landing extends React.Component {
render() {
return (
<div>
<input type="text" onChange={() => {console.log("HERE")}} />
<br />
</div>
);
}
}
我已经尝试将我的代码从ES6更改为ES5语法,但我仍然没有得到显示的单词我知道我应该期待“HERE”在终端显示中出现,但我无法得到它出现了。