Skip to content

Commit 10bfe93

Browse files
Composition API example of SFC (#2145)
* Composition API version * fix * Fix problems with new SFC example Co-authored-by: Peter Kompasz <[email protected]>
1 parent 6ba8270 commit 10bfe93

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/guide/scaling-up/sfc.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Vue Single-File Components (a.k.a. `*.vue` files, abbreviated as **SFC**) is a special file format that allows us to encapsulate the template, logic, **and** styling of a Vue component in a single file. Here's an example SFC:
66

7+
<div class="options-api">
8+
79
```vue
810
<script>
911
export default {
@@ -27,6 +29,30 @@ export default {
2729
</style>
2830
```
2931

32+
</div>
33+
34+
<div class="composition-api">
35+
36+
```vue
37+
<script setup>
38+
import { ref } from 'vue'
39+
const greeting = ref('Hello World!')
40+
</script>
41+
42+
<template>
43+
<p class="greeting">{{ greeting }}</p>
44+
</template>
45+
46+
<style>
47+
.greeting {
48+
color: red;
49+
font-weight: bold;
50+
}
51+
</style>
52+
```
53+
54+
</div>
55+
3056
As we can see, Vue SFC is a natural extension of the classic trio of HTML, CSS and JavaScript. The `<template>`, `<script>`, and `<style>` blocks encapsulate and colocate the view, logic and styling of a component in the same file. The full syntax is defined in the [SFC Syntax Specification](/api/sfc-spec).
3157

3258
## Why SFC {#why-sfc}

0 commit comments

Comments
 (0)