Examples
- Introduction
- Reactivity
- Props
- Logic
- Events
- Bindings
- Lifecycle
- Stores
- Motion
- Transitions
- Animations
- Easing
- SVG
- Actions
- Classes
- Component composition
- Context API
- Special elements
- Module context
- Debugging
- 7GUIs
- Miscellaneous
App.svelte
9
1
2
3
4
5
6
7
›
⌄
<script>
let name = '';
</script>
<input bind:value={name} placeholder="enter your name" />
<p>Hello {name || 'stranger'}!</p>
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
›
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
/* App.svelte generated by Svelte v4.2.19 */
import {
SvelteComponent,
append,
attr,
detach,
element,
init,
insert,
listen,
noop,
safe_not_equal,
set_data,
set_input_value,
space,
text
} from "svelte/internal";
import "svelte/internal/disclose-version";
function create_fragment(ctx) {
let input;
let t0;
let p;
let t1;
let t2_value = (/*name*/ ctx[0] || 'stranger') + "";
let t2;
let t3;
let mounted;
let dispose;
return {
c() {
input = element("input");
t0 = space();
p = element("p");
t1 = text("Hello ");
t2 = text(t2_value);
t3 = text("!");
attr(input, "placeholder", "enter your name");
},
m(target, anchor) {
insert(target, input, anchor);
set_input_value(input, /*name*/ ctx[0]);
insert(target, t0, anchor);
insert(target, p, anchor);
append(p, t1);
append(p, t2);
append(p, t3);
if (!mounted) {
dispose = listen(input, "input", /*input_input_handler*/ ctx[1]);
mounted = true;
}
},
p(ctx, [dirty]) {
if (dirty & /*name*/ 1 && input.value !== /*name*/ ctx[0]) {
set_input_value(input, /*name*/ ctx[0]);
}
if (dirty & /*name*/ 1 && t2_value !== (t2_value = (/*name*/ ctx[0] || 'stranger') + "")) set_data(t2, t2_value);
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(input);
detach(t0);
detach(p);
}
mounted = false;
dispose();
}
};
}
function instance($$self, $$props, $$invalidate) {
let name = '';
function input_input_handler() {
name = this.value;
$$invalidate(0, name);
}
return [name, input_input_handler];
}
class App extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal, {});
}
}
export default App;
result = svelte.compile(source, {
generate:
css:
});9
1
›
/* Add a <style> tag to see compiled CSS */