-
Notifications
You must be signed in to change notification settings - Fork 8
/
vue2.html
96 lines (91 loc) · 2.28 KB
/
vue2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue2</title>
</head>
<body>
<div id="app"></div>
<script type="module">
import Vue from './vue/vue2.js';
const HelloComponent = {
emits: ['greet'],
data() {
return {
firstName: 'John',
lastName: 'Doe'
};
},
computed: {
fullName() {
return this.firstName + ' ' + this.lastName;
}
},
updated() {
this.$emit('greet', this.firstName);
},
template: `
<div>
<h1>{{ fullName }}</h1>
<slot></slot>
</div>
`
};
const app = new Vue({
el: '#app',
components: {
HelloComponent
},
data: {
message: 'Hello, Vue!',
inputValue: 'ChatGPT'
},
watch: {
message(newValue, oldValue) {
console.log('Message changed:', oldValue, ' -> ', newValue);
},
inputValue(newValue, oldValue) {
console.log('InputValue changed:', oldValue, ' -> ', newValue);
}
},
methods: {
greetMessage(message) {
this.$emit('greet', message);
},
updateMessage(newMessage) {
this.message = newMessage;
}
},
beforeMount() {
console.log('beforeMount hook');
},
mounted() {
console.log('mounted hook');
},
beforeUpdate() {
console.log('beforeUpdate hook');
},
updated() {
console.log('updated hook');
},
template: `
<div>
<HelloComponent v-on:greet="greetMessage">
<p>{{ message }}</p>
</HelloComponent>
<input v-model="inputValue" type="text">
<p v-text="inputValue"></p>
</div>
`
});
app.$on('greet', (message) => {
console.log('Greet:', message);
});
app.inputValue = 'OpenAI';
app.HelloComponent.firstName = 'Tom';
app.updateMessage('Hello, World!');
window.app = app;
</script>
</body>
</html>