You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All three sections — script, styles and markup — are optional.
7
+
以下の3つのセクション — script, styles, markup — は任意です。
8
8
9
9
<!-- prettier-ignore -->
10
10
```svelte
11
11
/// file: MyComponent.svelte
12
12
<script module>
13
-
// module-level logic goes here
14
-
// (you will rarely use this)
13
+
// モジュールレベルのロジックはここに書きます
14
+
// (ほとんど使うことはありません)
15
15
</script>
16
16
17
17
<script>
18
-
// instance-level logic goes here
18
+
// インスタンスレベルのロジックはここに書きます
19
19
</script>
20
20
21
-
<!-- markup (zero or more items) goes here -->
21
+
<!-- マークアップ (0行以上) はここに書きます -->
22
22
23
23
<style>
24
-
/* styles go here */
24
+
/* スタイルはここに書きます */
25
25
</style>
26
26
```
27
27
28
28
## `<script>`
29
29
30
-
A `<script>`block contains JavaScript (or TypeScript, when adding the `lang="ts"` attribute) that runs when a component instance is created. Variables declared (or imported) at the top level can be referenced in the component's markup.
In addition to normal JavaScript, you can use _runes_to declare [component props]($props) and add reactivity to your component. Runes are covered in the next section.
A `<script>`tag with a `module`attribute runs once when the module first evaluates, rather than for each component instance. Variables declared in this block can be referenced elsewhere in the component, but not vice versa.
@@ -48,24 +48,24 @@ A `<script>` tag with a `module` attribute runs once when the module first evalu
48
48
</script>
49
49
```
50
50
51
-
You can `export`bindings from this block, and they will become exports of the compiled module. You cannot `export default`, since the default export is the component itself.
> [!NOTE]If you are using TypeScript and import such exports from a `module`block into a `.ts`file, make sure to have your editor setup so that TypeScript knows about them. This is the case for our VS Code extension and the IntelliJ plugin, but in other cases you might need to setup our [TypeScript editor plugin](https://www.npmjs.com/package/typescript-svelte-plugin).
0 commit comments