【发布时间】:2019-03-12 17:48:57
【问题描述】:
我已经创建了一个带有 vue 和 Laravel 后端的消息系统,我想将我的消息(Jim,我当前登录的人)在右侧分组为蓝色和 Debbie(我的用户) m 与)在左侧使用 flexbox 以黄色显示。喜欢 Facebook 或 Twitter:
模拟 JSON 输出
{
"0": {
"name": "Debbie",
"message": "Good, Thinks for asking."
},
"1": {
"name": "Jim",
"message": "I'm good, how are you?"
},
"2": {
"name": "Debbie",
"message": "How are you?"
},
"3": {
"name": "Jim",
"message": "Hi Debbie"
},
"4": {
"name": "Debbie",
"message": "Hi Jim"
}
}
我必须通过我的 JSON API 发送什么来从任何其他用户和他们的消息中识别自己?或者有没有一种方法可以做到这一点而无需更改 JSON 输出?
我将如何使用 flexbox 实现这个 into this messenger system that I've built?我正在使用的主要组件是会话消息组件:
Vue.component('conversation-messages',{
template: '#conversation-messages',
props: ['conversationId'],
data: function() {
return {
messages: [],
url: ''
}
},
mounted() {
console.log("message mounted")
this.getOldMessages(this.conversationId);
},
});
Here's a link to this question being answered only using css.
来自 CSS 链接,了解如何创建像 FB 这样的聊天气泡系统
使用浮动而非 Flexbox 的链接中的 HTML 结构示例
<ul>
<li class="him">By Other User</li>
<li class="me">By this User, first message</li>
<li class="me">By this User, secondmessage</li>
<li class="me">By this User, third message</li>
<li class="me">By this User, fourth message</li>
</ul>
链接中答案的 CSS 示例
ul{
list-style: none;
margin: 0;
padding: 0;
}
ul li{
display:inline-block;
clear: both;
padding: 20px;
border-radius: 30px;
margin-bottom: 2px;
font-family: Helvetica, Arial, sans-serif;
}
.him{
background: #eee;
float: left;
}
.me{
float: right;
background: #0084ff;
color: #fff;
}
.him + .me{
border-bottom-right-radius: 5px;
}
.me + .me{
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
.me:last-of-type {
border-bottom-right-radius: 30px;
}
【问题讨论】:
标签: javascript css vue.js vuejs2 flexbox