Logo
Section 1 / 2

导出现有条目

学习如何实现导出数据以供后续使用功能。

导入

导出现有条目

学习如何实现导出数据以供后续使用功能。

No configuration found for ID: b61990fa695b4a42b68d3ac93045c4e1f340402d8c491e27d2aa9c162ba1f0b6

代码应如下所示:

1<script> 2 import Button from './Button.svelte' 3 4 export let student = null; 5</script> 6 7<Button 8 text={student ? '导出学生' : '导出'} 9 onClick={() => {}} 10/>

代码应如下所示:

1<script> 2 import Button from './Button.svelte' 3export let student = null; 4</script> 5<Button 6text={student ? '导出学生' : '导出'} 7onClick={() => {}} 8/>
1<!-- 使用原始文件名进行下载 --> 2<a href="/resources/report.pdf" download> 3 4<!-- 使用自定义文件名进行下载 --> 5<a href="/resources/report.pdf" download="latest-reports.pdf">
1data:[<mediatype>][;base64],<data>
1'data:text/plain;charset=utf-8,' + encodeURIComponent(data)
1const exportStudent = () => { 2 const data = JSON.stringify(student || $state.students); 3 const link = document.createElement('a'); 4 5 link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data)); 6 link.setAttribute('download', 'students.json'); 7 link.style.display = 'none'; 8 9 document.body.appendChild(link); 10 11 link.click(); 12 13 document.body.removeChild(link); 14}
...
动态插入的下载链接

No configuration found for ID: a0b91854ec508319e173a9470b5d71ce2b118ff2b1f2ba679fb7ed79886803f4

构建详情视图

导入到表格