1 Star 12 Fork 22

DEV-Edu/frontend-mvvm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TestChatGroup.html 4.46 KB
一键复制 编辑 原始数据 按行查看 历史
DEV-Edu 提交于 2024-08-27 09:23 . auto commit
<!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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dev-edu/frontend-mvvm.git
git@gitee.com:dev-edu/frontend-mvvm.git
dev-edu
frontend-mvvm
frontend-mvvm
master

搜索帮助