Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Svelteで作るWebComponents / svelte-web-components

やし
October 30, 2019

Svelteで作るWebComponents / svelte-web-components

Vue.js Night #1
https://giftee.connpass.com/event/150145/
にて発表した資料です。

やし

October 30, 2019
Tweet

More Decks by やし

Other Decks in Programming

Transcript

  1. <template> <h1>Hello {{ name }}</h1> </template> <script> export default {

    data() { return { name: "world" }; } }; </script> <script> let name = "world"; </script> <h1>Hello {name}</h1> 7VF 4WFMUF Svelte syntax
  2. <template> <h1>Hello world</h1> </template> <style scoped> h1 { color: red;

    } </style> <style> h1 { color: red; } </style> <h1>Hello world </h1> Svelte syntax 7VF 4WFMUF
  3. <template> <div> <div>count: {{ count }}</div> <button @click="handleClick"> button</button> </div>

    </template> <script> export default { data() { return { count: 0 }; }, methods: { handleClick() { this.count += 1; } } }; </script> <script> let count = 0; function handleClick() { count += 1; } </script> <div>count: {count}</div> <button on:click={handleClick} >button</button> Svelte syntax 7VF 4WFMUF
  4. Svelte syntax • data binding, style binding • if, eachͳͲͷϒϩοΫ

    • slot • ϥΠϑαΠΫϧϝιου • (؆қతͳ)store • transition, animation • (ҰԠ)contextAPI
  5. <script> export let title = "Svelte Card"; export let message

    = "This is card component created by svelte"; let selected = false; function handleOnClick() { selected = !selected; } </script> <style> /* লུ */ </style> <svelte:options tag="svelte-card" /> <div class="card" class:selected on:click={handleOnClick}> <div class="card-title">{title}</div> <div class="card-body">{message}</div> <slot name="footer" /> </div> Svelte CustomElement
  6. <template> <div class="container"> <h1>Svelte x {{ name }}</h1> <div class="content-wrapper">

    <template v-for="card in cards"> <svelte- card :title="card.title" :message="card.message" :key="car d.id"> <svelte-button slot="footer" @click="handleButtonOnClick" ></svelte-button> </svelte-card> </template> </div> </div> </template> <script> import "../public/svelte-elements"; WebComponents in Vue
  7. return ( <div className="container"> <h1>Svelte x {props.name}</h1> <div className="content-wrapper"> {cards.map((card,

    i) => ( <svelte- card title={card.title} message={card.message} key= {i}> <svelte-button slot="footer" onClick={handleButtonOnClick} ></svelte-button> </svelte-card> ))} </div> </div> ); WebComponents in React