-
Notifications
You must be signed in to change notification settings - Fork 1
/
draft.html
81 lines (61 loc) · 1.51 KB
/
draft.html
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
<script setup>
import { ref } from 'vue';
const counter = ref(0);
const name = ref('Huy');
function increment() {
counter.value += 1;
}
function changeName() {
name.value = 'ellie';
}
const text = ref('');
const errors = ref(null);
const courses = ref([]);
async function fetchCourses() {
const response = await getCourseService();
courses.value = response.data;
}
function submit(e) {
// Check form valid -> if not -> error
if (!text) {
errors.value = 'name is required'
return;
}
// submit
// axios.post('api/submit-form', { name: dsad, age: dsadsa })
// redirect to confirm
}
fetchCourses();
onMounted(() => {
})
</script>
<template>
<h1 :id="name">This is Login page {{ counter }} {{ name }}</h1>
<button @click="increment">Increment</button>
<button @click="changeName">ChangeName</button>
<form @submit.prevent="submit">
<input v-model="text" name="name">
<div v-if="errors" class="text-sm text-red-500">{{ errors }}</div>
<button type="submit">Submit</button>
</form>
<div>{{ text }}</div>
<ul>
<li v-for="course in courses">{{
course.name
}}</li>
</ul>
<Student name="Max" age="28" />
<Student name="Ellie" age="27" />
</template>
// create state -> gan state vao dom text content hoac la attribute
// cung co the gan event handler
// function
- perform side effect:
- update state
<template>
<div>{{ name }} {{ age }}</div>
</template>
<script setup>
defineProps(['name', 'age'])
const internalState = ref(0);
</script>