1 回答
![?](http://img1.sycdn.imooc.com/5458472300015f4702200220-100-100.jpg)
TA贡献1836条经验 获得超13个赞
我没有看到任何index服务器渲染视图。尝试创建一个index.html作为您的主页并在listing.js.
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
如果你想weatha-picka.html作为一个静态页面,只需像这样返回它:
app.get('/weatha-picka', (req, res) => {
res.sendFile(__dirname + '/weatha-picka.html');
});
此外,如果您想创建更多视图 as weatha-picka,请尝试使用ejs模板模块。下面是 ejs 和 express 的示例。
在listing.js:
const express = require('express');
var app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, './public')); // ejs engine looks for ejs files in public folder
app.get('/weatha-picka', function (req, res) {
res.render('weatha-picka', {});
});
在/public文件夹中,创建weatha-picka.ejs模板文件:
<html>
<head>
<title>EJS template</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- Use ejs template and html here -->
</body>
</html>
添加回答
举报