我必须将 API 响应复制到剪贴板(ctrl+c)。我试图通过邮递员测试部分中的 document.executeCommand 来完成。但我收到文档未定义错误。
有没有其他方法可以完成我的要求。
EDIT: 我已经做到了。
尝试这个:
let template =
`
<textarea id='copy' style='width:35%'></textarea>
<script>
pm.getData(function (error, data)
{
var node = document.getElementById('copy');
node.textContent = data.response;
var selection = document.getSelection();
selection.removeAllRanges();
node.select();
document.execCommand('copy');
selection.removeAllRanges();
document.getElementById('copy').textContent = 'Response copied to clipboard!';
});
</script>
`;
pm.visualizer.set(template, {
response: responseBody
});
之前的回答:
您可以将其以可三次点击(突出显示)的格式打印到控制台,从而使其复制速度更快一些。我在我的一个系列中使用了这种技术。
我的示例响应采用 JSON 格式,但我想要的部分是嵌套的,因此我使用以下日志语句:
console.info(ζ.name + " Results:\n\r", ζ.results.data[0]);
哪里的ζ.results.data[0]
部分是一个方便的、可点击三次的 JSON 字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)