gpt4 book ai didi

svelte - 用 Svelte 逐行写入文本文件的内容

转载 作者:行者123 更新时间:2023-12-05 01:07:18 27 4
gpt4 key购买 nike

我在打开一个txt文件的svelte中编写了这段代码,并将它写在一个html段落中。这是代码:

<input type='file' multiple bind:files'>

{#if files}
<h2>Files selected: </h2>
{#each Array.from(files) as file}
<p> IThe imported file is: {file.name}</p>
{#await file.text() then text}
<p>{text}</p>
{/await}
{/each}
{/if}

示例文件是这样的:

beans
spam
donut

但它给了我这个:

beans spam donut

如何为文本中的每一行创建一个新行(段落或 <br>)?

最佳答案

这个怎么样?只需在换行符上拆分并创建一个新的 p 标签。

<script>
let files;
</script>

<input type='file' multiple bind:files />

{#if files}
<h2>Files selected: </h2>
{#each Array.from(files) as file}
<p> IThe imported file is: {file.name}</p>
{#await file.text() then text}
{#each text.split('\n') as line }
<p>{line}</p>
{/each}
{/await}
{/each}
{/if}

关于svelte - 用 Svelte 逐行写入文本文件的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67760803/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com