-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·45 lines (39 loc) · 1.21 KB
/
app.js
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
new Vue({
el: '#app',
data: {
message: '',
chat: [],
yodaReplying: false,
},
created: function () {
if (sessionStorage.getItem('yodachat')) {
try {
this.chat = JSON.parse(sessionStorage.getItem('yodachat'));
} catch (e) {
sessionStorage.removeItem('yodachat');
}
}
},
methods: {
send() {
if (!this.message)
return;
let message = {value: this.message, reply: false};
this.chat.push(message);
sessionStorage.setItem('yodachat', JSON.stringify(this.chat));
axios.post('back/chat.php', {
message: this.message
}).then(response => {
let message = {value: response.data, reply: true};
this.chat.push(message);
sessionStorage.setItem('yodachat', JSON.stringify(this.chat));
this.yodaReplying = false;
window.scrollTo(0, document.body.scrollHeight);
}).catch(e => {
console.log(e);
});
this.message = '';
this.yodaReplying = true;
}
}
});