【问题标题】:Inserting a new line into a template string? [duplicate]在模板字符串中插入新行? [复制]
【发布时间】:2018-08-26 10:06:22
【问题描述】:

我试过把它分成两行:

const templateString = `this is my template 
                        string`

我也试过了:

const templateString = `this is my template\n string`

但这些都不起作用。 templateString 仍然是一行。如何创建多行模板字符串?

【问题讨论】:

  • 你的first syntax 应该可以工作。
  • 您的意思是在客户端将其呈现为 HTML?那将需要一个
    标签。如果您添加
    标签,您的第一次尝试是正确的。
  • 多行是the expected behaviour,它是需要特殊处理的换行符删除。
  • 两种语法都有效。 templateString怎么输出?
  • @scraaappy 我在 html 元素中输出它 - divp 标签

标签: javascript ecmascript-6 template-strings


【解决方案1】:

这需要<br> 标签。如果您添加<br> 标签,您的第一次尝试是正确的。

【讨论】:

  • 只是显示为this is my template <br> string,实际上并没有打破界限
  • 同上评论
  • @enf0rcer 请举例说明该答案如何解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-07
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
相关资源
最近更新 更多