This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.html
112 lines (103 loc) · 2.38 KB
/
chat.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue components</title>
</head>
<body>
<div id="app">
<message></message>
<br />
<chat></chat>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Faker/3.1.0/faker.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
let bus = new Vue();
let Message = {
data() {
return {
user: null
};
},
template: `
<div class="message" v-if="user">
{{ user.name }} has just entered the room!
</div>
`,
mounted() {
bus.$on("user:joined", user => {
this.user = user;
setTimeout(() => {
this.user = null;
}, 1000);
});
}
};
let User = {
props: ["user"],
template: `
<div class="user">
{{ user.name }}
</div>
`
};
let Users = {
components: {
User
},
data() {
return {
/*
users: [
{ id: 1, name: "Clément" },
{ id: 2, name: "Tomy" }
]
*/
users: []
};
},
template: `
<div class="users">
<user v-for="user in users" :key="user.id" :user='user'></user>
</div>
`,
mounted() {
/*
setInterval(() => {
this.users.push({ id: Date.now(), name: faker.name.findName() });
}, 2000);
*/
bus.$on("user:joined", user => {
//console.log("Je conduis le bus");
this.users.push(user);
});
}
};
setInterval(() => {
bus.$emit("user:joined", {
id: Date.now(),
name: faker.name.findName()
});
}, 2000);
let Chat = {
components: {
Users
},
template: `
<div class="chat">
<users></users>
</div>
`
};
let app = new Vue({
el: "#app",
components: {
Chat,
Message
}
});
</script>
</body>
</html>