• vue 聊天页


    <template>
      <div class="lick-container" @keyup.enter="sendMessage">
        <div class="chat-content-container">
          <div class="header">联通</div>
          <div class="body" ref="msgBody">
            <div
              class="message"
              v-for="(message, index) in messageList"
              :key="index"
              :class="{ self: message.type === 'self' }"
            >
              <div class="avatar"></div>
              <div class="trangle"></div>
              <div class="content">{{ message.content }}</div>
            </div>
          </div>
        </div>
        <div class="type-container">
          <input class="type-input" v-model="keyWord" />
          <div class="send-btn" @click="sendMessage">发送</div>
        </div>
      </div>
    </template>
    <script>
    export default {
      data() {
        return {
          keyWord: "",
          messageList: [
            { type: "oppsite", content: "测试1" },
            { type: "oppsite", content: "测试2!" },
          ],
          simpWordList: [
            "测试...",
            "测试...",
            "测试...",
            "测试...",
            "测试...",
            "测试...",
            "测试...",
          ],
        };
      },
      // mounted() {
      //   // setInterval(this.addReply, 5000)
      // },
      methods: {
        addReply() {
          const { simpWordList } = this;
          const length = simpWordList.length;
          const index = Math.floor(Math.random() * length);
          this.messageList.push({ type: "oppsite", content: simpWordList[index] });
          this.$nextTick(() => {
            this.$refs.msgBody.scrollTop = this.$refs.msgBody.scrollHeight;
          });
        },
        sendMessage() {
          if (this.keyWord === "") {
            return;
          }
          this.messageList.push({ type: "self", content: this.keyWord });
          this.addReply();
          this.keyWord = "";
        },
      },
    };
    </script>
    <style lang="scss">
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    .br-10px {
      border-radius: 10px;
    }
    .lick-container {
      height: 100%;
      margin: 0 auto;
    }
    .chat-content-container {
      .header {
         100%;
        height: 79px;
        background: #ededed;
        border-bottom: 3px solid #e9e9e9;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 30px;
      }
      .body {
         100%;
        height: calc(100vh - 158px);
        overflow: auto;
        &::-webkit-scrollbar {
           0 !important;
        }
        background: #ededed;
        padding-top: 10px;
        .message {
          display: flex;
          align-items: center;
          margin-bottom: 10px;
          margin-left: 15px;
          &.self {
            flex-direction: row-reverse;
            margin-left: auto;
            margin-right: 15px;
            .trangle {
              border: none;
              border-top: 12.5px solid transparent;
              border-left: 12.5px solid rgb(149, 236, 105);
              border-bottom: 12.5px solid transparent;
              margin-left: 0;
              margin-right: 20px;
            }
            .content {
              background: rgb(149, 236, 105);
            }
            .avatar {
              &::before {
                content: "B";
                top: 50%;
                color: #fff;
                font-size: 30px;
                left: 50%;
                transform: translate(-50%, -50%);
                position: absolute;
              }
            }
          }
          .avatar {
             75px;
            height: 75px;
            position: relative;
            background: #25e465;
            background-size: cover;
            border-radius: 10px;
            text-align: center;
            box-shadow: 1px 3px 4px 1px rgba(0, 0, 0, 0.5);
            &::before {
              content: "C";
              top: 50%;
              color: #fff;
              font-size: 30px;
              left: 50%;
              transform: translate(-50%, -50%);
              position: absolute;
            }
          }
          .trangle {
             0;
            height: 0;
            border-right: 12.5px solid #fff;
            border-bottom: 12.5px solid transparent;
            border-top: 12.5px solid transparent;
            margin-left: 20px;
          }
          .content {
            min-height: 75px;
            max- 505px;
            display: flex;
            align-items: center;
            font-size: 30px;
            padding: 20px 20px;
            background: #fff;
            border-radius: 10px;
          }
        }
      }
    }
    .type-container {
       100%;
      height: 79px;
      background: #ededed;
      border-top: 3px solid #e9e9e9;
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      .type-input {
        border: none;
         75%;
        height: 59px;
        font-size: 30px;
        border-radius: 10px;
        outline: none;
        text-indent: 30px;
      }
      .send-btn {
        background: rgb(80, 236, 105);
         15%;
        height: 59px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 30px;
        color: #fff;
        cursor: pointer;
      }
    }
    </style>
    
    
  • 相关阅读:
    springmvc实现文件上传
    springmvc乱码及restful
    springmvc数据的处理
    springmvc跳转方式
    controller配置
    SpringMVC Annotation
    SpringMVC基本包
    第一章 面向对象软件工程与UML
    Oracle数据库之PL/SQL程序基础设计
    thinkphp5 给CSS JS 添加版本号
  • 原文地址:https://www.cnblogs.com/7c89/p/15876889.html
Copyright © 2020-2023  润新知