<script> let employees = [ { name: "Parke Béla", salary: 2850000 }, { name: "Lenke Attila", salary: 2243500 }, { name: "Tron Ferenc", salary: 2150500 } ]; </script> <h1>Főoldal</h1> <table> {#each employees as emp} <tr> <td>{emp.name}</td> <td>{emp.salary}</td> </tr> {/each} </table>
<script> let data = new Array(); function get() { let employees = [ { name: "Parke Béla", salary: 2850000 }, { name: "Lenke Attila", salary: 2243500 }, { name: "Tron Ferenc", salary: 2150500 } ]; data = employees; } </script> <h1>Főoldal</h1> <button on:click={get}>Megkap</button> <table> {#each data as emp} <tr> <td>{emp.name}</td> <td>{emp.salary}</td> </tr> {/each} </table>
A függvényben az adatok jöhetnek fetch() függvénnyel is.