代码拉取完成,页面将自动刷新
同步操作将从 DEV-Edu/frontend-mvvm 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<!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="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 "./core/index.js";
let chat = 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(function () {
axios({
method: "get",
url: "https://developer.duyiedu.com/edu/groupChat/getMsgList"
}).then(function (resp) {
chat.msgList = resp.data;
var ul = document.getElementsByTagName("ul")[0];
ul.scrollTop = ul.scrollHeight;
}).catch(function (event) {
console.log(event);
});
}, 1000);
}
});
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。