【问题标题】:koa2 template string can not display properlykoa2 模板字符串无法正常显示
【发布时间】:2017-06-07 10:26:03
【问题描述】:

我正在安装外套 2.0 和节点 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);

【问题讨论】:

    标签: koa2


    【解决方案1】:

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

    const Koa = require('koa'); const app = new Koa();
    
    app.use(ctx => {
        const date = new Date();
        ctx.body = `Hello World ${date}`;
    });
    
    app.listen(3000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多