-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
162 lines (147 loc) · 3.61 KB
/
test.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script> -->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
<style>
* {
margin: 0px;
padding: 0px;
}
.red {
color: red;
}
.blue {
color: blue;
}
#chat {
position: relative;
width: 400px;
height: 600px;
margin: 0px auto 0px auto;
border: 1px solid black;
}
.name {
position: relative;
width: 100%;
height: 30px;
margin: 10px 0px 0px 0px;
font-size: 0px;
}
.name span {
position: absolute;
display: block;
left: 0px;
top: 0px;
width: 100px;
height: 30px;
line-height: 30px;
margin: 0px;
padding: 0px 0px 0px 20px;
font-size: 16px;
}
.name input {
position: absolute;
display: block;
left: 80px;
top: 0px;
width: 200px;
height: 30px;
line-height: 30px;
border-radius: 5px;
border: 1px solid black;
outline: medium;
padding: 0px 0px 0px 10px;
font-size: 16px;
}
#sendMsg {
position: absolute;
width: 70%;
height: 30px;
border: 1px solid black;
left: 0px;
bottom: 5px;
border-radius: 5px;
padding: 0px 0px 0px 10px;
margin: 0px 0px 0px 20px;
font-size: 16px;
}
ul {
height: 500px;
margin: 10px 0px 0px 0px;
overflow-Y: scroll;
}
li {
list-style: none;
margin: 10px 0px 0px 20px;
}
button {
position: absolute;
width: 10%;
height: 30px;
border: 1px solid black;
right: 30px;
bottom: 5px;
border-radius: 5px;
font-size: 14px;
}
</style>
</head>
<body>
<div id="chat">
<div class="name">
<span>姓名:</span>
<input type="text" value="" v-model="name" placeholder="请输入用户名">
</div>
<ul>
<li v-for="(msg) in msgList">
<div v-bind:class="{red: msg.name == name, blue: msg.name != name}">{{msg.name}}: <span>{{msg.msg}}</span></div>
</li>
</ul>
<input type="text" value="" v-model="sendText" id="sendMsg" placeholder="请输入内容,按回车键入">
<button v-on:click="sendMsg">发送</button>
</div>
<script type="module">
import Due from "./miniVue/index.js";
import { log } from './miniVue/instance/render.js'
window.app = new Due({
el: "#chat",
data: {
name: "",
msgList: [],
sendText: "",
kkk: "blue"
},
methods: {
sendMsg: function () {
axios({
method: "get",
url: "https://developer.duyiedu.com/edu/groupChat/sendMsg?name=" + this.name + "&msg=" + this.sendText
}).then(function (resp) {
console.log("发送成功");
}).catch(function () {
console.log("发送失败");
});
this.sendText = "";
},
},
created: function () {
setInterval(() => {
axios({
method: "get",
url: "https://developer.duyiedu.com/edu/groupChat/getMsgList"
}).then((resp) => {
this.msgList = resp.data;
var ul = document.getElementsByTagName("ul")[0];
ul.scrollTop = ul.scrollHeight;
}).catch(function (event) {
console.log(event);
});
}, 1000);
}
});
</script>
</body>
</html>