-
Notifications
You must be signed in to change notification settings - Fork 0
/
learning_vue.html
121 lines (108 loc) · 3.36 KB
/
learning_vue.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trying Vue Js</title>
</head>
<body>
<script src="https://unpkg.com/vue@next"></script>
<div id="app">
<p>{{ content }}</p>
<input type="text" name="content" v-model="content" @keyup.enter="addToTodo" v-if="!todoInputHidden">
<button @click.right.prevent="showAlert($event)">Right Click Here</button>
<hr>
<span v-bind:title="content">
Hover your mouse over me for a few seconds to see my dynamically bound
title!
</span>
<hr>
<h4>Todo App</h4>
<ol>
<li v-for="(todo, index) in todos">
<div>
{{todo}} <button @click='deleteItem(index)'>Delete</button>
</div>
</li>
</ol>
<h4>Todo Item Component Based TODO</h4>
<ol>
<todo-item v-for="(todo, index) in todos" :todo="todo" :index="index" @delete="deleteItem($event)">
</todo-item>
</ol>
<hr>
</div>
<script>
const app = Vue.createApp({
data() {
return {
content: "",
todoInputHidden: false,
todos: [],
}
},
watch: {
content(newContent, oldContent) {
if (newContent.indexOf('..') != -1) {
this.content = newContent.replace("..", ".");
this.addToTodo();
}
}
},
created() {
console.log("App Created")
},
mounted() {
console.log("App Mounted");
// setTimeout(() => {
// this.todoInputHidden = true;
// }, 2000);
},
updated() {
console.log("App Updated");
},
methods: {
showAlert(event) {
alert(event.button);
},
addToTodo() {
if (this.content.length == 0) return;
this.todos.push(this.content);
this.content = "";
},
deleteItem(index) {
this.todos.splice(index, 1);
}
},
});
app.component("todo-item", {
template: `<li>{{ todo }} <button @click='$emit("delete", index)'>Delete</button></li>`,
props: {
todo: {
type: String,
required: true,
validator: value => {
return value.length > 0;
}
},
index: {
type: Number,
required: true,
}
},
emits: ['delete'],
updated() {
console.log("TODO ITEM UPDATED");
},
mounted() {
console.log("TODO ITEM Mounted");
},
created() {
console.log("TODO ITEM Created");
},
});
app.mount("#app");
</script>
</body>
</html>