这是用户在 2024-5-1 14:03 为 https://svelte.dev/examples/default-values 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Skip to main content

Examples

App.svelte
Nested.svelte
<script>
export let answer = 'a mystery';
</script>

<p>The answer is {answer}</p>

/* Nested.svelte generated by Svelte v4.2.15 */
import {
SvelteComponent,
append,
detach,
element,
init,
insert,
noop,
safe_not_equal,
set_data,
text
} from "svelte/internal";

import "svelte/internal/disclose-version";

function create_fragment(ctx) {
let p;
let t0;
let t1;

return {
c() {
p = element("p");
t0 = text("The answer is ");
t1 = text(/*answer*/ ctx[0]);
},
m(target, anchor) {
insert(target, p, anchor);
append(p, t0);
append(p, t1);
},
p(ctx, [dirty]) {
if (dirty & /*answer*/ 1) set_data(t1, /*answer*/ ctx[0]);
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(p);
}
}
};
}

function instance($$self, $$props, $$invalidate) {
let { answer = 'a mystery' } = $$props;

$$self.$$set = $$props => {
if ('answer' in $$props) $$invalidate(0, answer = $$props.answer);
};

return [answer];
}

class Nested extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal, { answer: 0 });
}
}

export default Nested;
result = svelte.compile(source, {
generate:
css:
});
/* Add a <style> tag to see compiled CSS */
Default values • Svelte Examples