/
githubmirror
/
socket.io
Обзор
Документация
Войти
/
githubmirror
/
socket.io
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/private-messaging/src/components/MessagePanel.vue
101 строка
2 KB
Damien Arrachequesne
docs(examples): 1st part of the "private messaging" example
10 фев 2021, 02:33
Не верифицирован
10 фев 2021, 02:33
8b404f4
Код
Авторство
О чём код?
<template> <div> <div class="header"> <status-icon :connected="user.connected" />{{ user.username }} </div> <ul class="messages"> <li v-for="(message, index) in user.messages" :key="index" class="message" > <div v-if="displaySender(message, index)" class="sender"> {{ message.fromSelf ? "(yourself)" : user.username }} </div> {{ message.content }} </li> </ul> <form @submit.prevent="onSubmit" class="form"> <textarea v-model="input" placeholder="Your message..." class="input" /> <button :disabled="!isValid" class="send-button">Send</button> </form> </div> </template> <script> import StatusIcon from "./StatusIcon"; export default { name: "MessagePanel", components: { StatusIcon, }, props: { user: Object, }, data() { return { input: "", }; }, methods: { onSubmit() { this.$emit("input", this.input); this.input = ""; }, displaySender(message, index) { return ( index === 0 || this.user.messages[index - 1].fromSelf !== this.user.messages[index].fromSelf ); }, }, computed: { isValid() { return this.input.length > 0; }, }, }; </script> <style scoped> .header { line-height: 40px; padding: 10px 20px; border-bottom: 1px solid #dddddd; } .messages { margin: 0; padding: 20px; } .message { list-style: none; } .sender { font-weight: bold; margin-top: 5px; } .form { padding: 10px; } .input { width: 80%; resize: none; padding: 10px; line-height: 1.5; border-radius: 5px; border: 1px solid #000; } .send-button { vertical-align: top; } </style>