-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasics.txt
34 lines (24 loc) · 1.12 KB
/
basics.txt
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
SFC Single File Component
- it's a reusable self-contained block of code
- it has html,css and js together
Declarative rendering
- we can describe how html should look based on js state
- when state changes html updated automatically
- State that can trigger updates when changed are considered reactive.
- We can declare reactive state using Vue's reactive() API.
- reactive() only works on objects
import { reactive } from 'vue'
const counter = reactive({
count: 0
})
console.log(counter.count) // 0
counter.count++
- ref() can take any value type and create an object that exposes the inner value under a .value property.
import { ref } from 'vue'
const message = ref('Hello World!')
console.log(message.value) // "Hello World!"
message.value = 'Changed'
- Reactive state declared in the component's <script setup> block can be used directly in the template.
-This is how we can render dynamic text based on the value of the counter object and message ref, using mustaches syntax:
<h1>{{ message }}</h1>
<p>count is: {{ counter.count }}</p>