Skip to content

Instantly share code, notes, and snippets.

@b3b00
Created August 8, 2019 07:11
Show Gist options
  • Save b3b00/ee47828dfa88cc0324125ec1fd8930f4 to your computer and use it in GitHub Desktop.
Save b3b00/ee47828dfa88cc0324125ec1fd8930f4 to your computer and use it in GitHub Desktop.
svelte navigation / layout gist
<script>
import Box from './Box.svelte';
import C1 from './C1.svelte';
import C2 from './C2.svelte';
let display = "one";
let value = "one";
function one() {
display = "one";
value = "one";
}
function two() {
display = "two";
value = "two";
}
</script>
<button on:click={one}>one</button>
<button on:click={two}>two</button>
<p>value : {value}</p>
<p>display : {display}</p>
<Box>
{#if (display=="one")}
<C1/>
{:else if (display == "two")}
<C2/>
{:else}
<p>
default value
</p>
{/if}
<hr/>
<p>box footer - {value}</p>
</Box>
<style>
.box {
width: 300px;
border: 1px solid #aaa;
border-radius: 2px;
box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
padding: 1em;
margin: 0 0 1em 0;
}
</style>
<div class="box">
<slot></slot>
</div>
<script>
console.log("init C1");
</script>
<p>
component 1
</p>
<script>
console.log("init C2");
</script>
<p>
component 2
</p>
@b3b00
Copy link
Author

b3b00 commented Aug 8, 2019

also on svelte REPL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment