koa2模板字符串无法正常显示

koa2 template string can not display properly

我正在安装 coat 2.0 和 node 8.0,但是当我测试下面的代码时,它显示 Hello World ${date},不是 Hello World 6/7/2017。

const Koa = require('koa'); const app = new Koa();

app.use(ctx => {

const date = new Date();

ctx.body = 'Hello World ${date}';

});

app.listen(3000);

您需要在模板字符串中使用反引号 `:

const Koa = require('koa'); const app = new Koa();

app.use(ctx => {
    const date = new Date();
    ctx.body = `Hello World ${date}`;
});

app.listen(3000);