【问题标题】:Postman console log not allowing to write string in next line邮递员控制台日志不允许在下一行写入字符串
【发布时间】:2018-08-31 13:36:45
【问题描述】:

我正在尝试在 Postman 控制台中使用 \n 在多行上显示字符串。我该怎么做?

例子:

var mystr='line\n another line\n another line';
console.log(mystr);

期待:

line
another line
another line

获取:

lineanother lineanother line

注意:它在 Firefox 暂存器中按预期工作。

【问题讨论】:

  • 试试\\n 而不是\n
  • 试过:结果是:行\n 另一行\n 另一行
  • 也许试试 '\r\n'
  • \n\\n\r\n 在 Postman 控制台中没有任何作用。

标签: javascript postman postman-collection-runner


【解决方案1】:

Postman console log not allowing to write string in next line #1477

在postman GitHub上问了同样的问题,有解决办法我会在这里更新。

谢谢,@Danny Dainton :)

【讨论】:

    【解决方案2】:

    您可以像这样打印多行文本:

    console.log("hello", '\n', "world");
    

    在控制台中会这样显示:

    【讨论】:

      【解决方案3】:

      键入 3 次 console.log:

      console.log('linea1');
      console.log('linea2');
      console.log('linea3');

      【讨论】:

      • 但这每次都会创建一个新的时间戳。
      【解决方案4】:

      我认为您无法在 Postman 控制台中实现这一点 - 也许值得在 Postman github 项目上提出一个问题,是否还没有。

      我会建议做与 cmets 相同的事情,添加 \n 在除此之外的所有其他控制台中都有效,这很奇怪。

      我认为目前唯一的方法就是添加多个 console.log() 语句,让您的 vars 在新行上打印。

      另一种选择是将您需要的内容放入array - 这并不理想,但会在控制台中的单独行中为您提供信息。

      【讨论】:

      • 使用数组每次打印前导0: 行号,这样可以防止复制打印的行。
      猜你喜欢
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 2011-02-09
      相关资源
      最近更新 更多