hey, how are you?
聊天消息
Quasar 提供了一个名为 QChatMessage 的聊天组件,用于呈现 props 提供的数据。
TIP
当消息和头像一起使用但是缺少头像时,使用一个头像占位符。 To mix messages with avatar and without avatar in the same thread, use a placeholder avatar image.
QChatMessage API
QChatMessage API
props
13
slots
5
behavior
4
content
6
style
3
label-html
: Boolean
说明
渲染 label 时使用的 HTML 标签;这可能导致 XSS 攻击,所以确保提前对消息进行安全处理
name-html
: Boolean
说明
渲染名称时使用的 HTML 标签;这可能导致 XSS 攻击,所以确保提前对消息进行安全处理
text-html
: Boolean
说明
渲染文本时使用的 HTML 标签;这可能导致 XSS 攻击,所以确保提前对消息进行安全处理
stamp-html
: Boolean
说明
渲染时间戳时使用的 HTML 标签;这可能导致 XSS 攻击,所以确保提前对消息进行安全处理
用法
基础
TIP
使用 sent
属性指定作为发送一端的消息,另一端是接收方。
基础
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
:text="['hey, how are you?']"
sent
/>
<q-chat-message
:text="['doing fine, how r you?']"
/>
</div>
</div>
</template>
Copied to clipboard
doing fine, how r you?
昵称
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
name="me"
:text="['hey, how are you?']"
sent
/>
<q-chat-message
name="Jane"
:text="['doing fine, how r you?']"
/>
</div>
</div>
</template>
Copied to clipboard
me
hey, how are you?
Jane
doing fine, how r you?
头像
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
name="me"
avatar="https://cdn.quasar.dev/img/avatar1.jpg"
:text="['hey, how are you?']"
sent
/>
<q-chat-message
name="Jane"
avatar="https://cdn.quasar.dev/img/avatar2.jpg"
:text="['doing fine, how r you?']"
/>
</div>
</div>
</template>
Copied to clipboard

me
hey, how are you?

Jane
doing fine, how r you?
时间
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
name="me"
avatar="https://cdn.quasar.dev/img/avatar4.jpg"
:text="['hey, how are you?']"
sent
stamp="7 minutes ago"
/>
<q-chat-message
name="Jane"
avatar="https://cdn.quasar.dev/img/avatar3.jpg"
:text="[`doing fine, how r you?`]"
stamp="4 minutes ago"
/>
</div>
</div>
</template>
Copied to clipboard

me
hey, how are you?
7 minutes ago

Jane
doing fine, how r you?
4 minutes ago
标签
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
label="Sunday, 19th"
/>
<q-chat-message
name="me"
avatar="https://cdn.quasar.dev/img/avatar4.jpg"
:text="['hey, how are you?']"
sent
stamp="7 minutes ago"
/>
<q-chat-message
name="Jane"
avatar="https://cdn.quasar.dev/img/avatar3.jpg"
:text="['doing fine, how r you?']"
stamp="4 minutes ago"
/>
</div>
</div>
</template>
Copied to clipboard
Sunday, 19th

me
hey, how are you?
7 minutes ago

Jane
doing fine, how r you?
4 minutes ago
自定义
文字和背景的颜色
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
name="me"
avatar="https://cdn.quasar.dev/img/avatar1.jpg"
:text="['hey, how are you?']"
stamp="7 minutes ago"
sent
bg-color="amber-7"
/>
<q-chat-message
name="Jane"
avatar="https://cdn.quasar.dev/img/avatar5.jpg"
:text="['doing fine, how r you?']"
stamp="4 minutes ago"
text-color="white"
bg-color="primary"
/>
</div>
</div>
</template>
Copied to clipboard

me
hey, how are you?
7 minutes ago

Jane
doing fine, how r you?
4 minutes ago
大小
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
name="me"
avatar="https://cdn.quasar.dev/img/avatar3.jpg"
:text="['hey, how are you?']"
stamp="7 minutes ago"
sent
bg-color="amber-7"
/>
<q-chat-message
name="Jane"
avatar="https://cdn.quasar.dev/img/avatar5.jpg"
:text="[
'doing fine, how r you?',
'I just feel like typing a really, really, REALLY long message to annoy you...'
]"
size="6"
stamp="4 minutes ago"
text-color="white"
bg-color="primary"
/>
<q-chat-message
name="Jane"
avatar="https://cdn.quasar.dev/img/avatar5.jpg"
:text="['Did it work?']"
stamp="1 minutes ago"
size="8"
text-color="white"
bg-color="primary"
/>
</div>
</div>
</template>
Copied to clipboard

me
hey, how are you?
7 minutes ago

Jane
doing fine, how r you?
4 minutes ago
I just feel like typing a really, really, REALLY long message to annoy you...
4 minutes ago

Jane
Did it work?
1 minutes ago
插槽
默认插槽
Template
Style
All
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
name="me"
avatar="https://cdn.quasar.dev/img/avatar3.jpg"
stamp="7 minutes ago"
sent
text-color="white"
bg-color="primary"
>
<div>
Hey there!
</div>
<div>
Have you seen Quasar?
<img src="https://cdn.quasar.dev/img/discord-omq.png" class="my-emoticon">
</div>
</q-chat-message>
<q-chat-message
name="Jane"
avatar="https://cdn.quasar.dev/img/avatar5.jpg"
bg-color="amber"
>
<q-spinner-dots size="2rem" />
</q-chat-message>
</div>
</div>
</template>
Copied to clipboard

me
Hey there!
7 minutes ago
Have you seen Quasar? 

7 minutes ago

Jane
头像/时间/昵称 插槽
Template
Style
All
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
:text="['Have you seen Quasar?']"
sent
text-color="white"
bg-color="primary"
>
<template v-slot:name>me</template>
<template v-slot:stamp>7 minutes ago</template>
<template v-slot:avatar>
<img
class="q-message-avatar q-message-avatar--sent"
src="https://cdn.quasar.dev/img/avatar4.jpg"
>
</template>
</q-chat-message>
<q-chat-message
bg-color="amber"
>
<template v-slot:name>Mary</template>
<template v-slot:avatar>
<img
class="q-message-avatar q-message-avatar--received"
src="https://cdn.quasar.dev/img/avatar2.jpg"
>
</template>
<div>
Already building an app with it...
<img src="https://cdn.quasar.dev/img/discord-qeart.png" class="my-emoji">
</div>
<q-spinner-dots size="2rem" />
</q-chat-message>
</div>
</div>
</template>
Copied to clipboard

me
Have you seen Quasar?
7 minutes ago

Mary
Already building an app with it... 

消毒
WARNING
如果数据来自用户的输入,一定要对不信任的数据进行消毒处理。
对内容消毒
Template
<template>
<div class="q-pa-md row justify-center">
<div style="width: 100%; max-width: 400px">
<q-chat-message
name="<span class='text-positive'>不可信的来源</span>"
avatar="https://cdn.quasar.dev/img/avatar3.jpg"
:text="['hey, how are <strong>you</strong>?']"
stamp="7 minutes ago"
sent
bg-color="amber-7"
/>
<q-chat-message
name="<span class='text-negative'>Jane (可信的 name 但是不可信的 text)</span>"
name-html
avatar="https://cdn.quasar.dev/img/avatar5.jpg"
:text="[
'doing fine, how r you?',
'I just feel like typing a really, really, <strong>REALLY</strong> long message to annoy you...'
]"
size="6"
stamp="4 minutes ago"
text-color="white"
bg-color="primary"
/>
<q-chat-message
name="<span class='text-negative'>Jao (可信的)</span>"
name-html
avatar="https://cdn.quasar.dev/img/avatar5.jpg"
:text="['<strong>Did it work?</strong>']"
text-html
stamp="1 minutes ago"
size="8"
text-color="white"
bg-color="primary"
/>
</div>
</div>
</template>
Copied to clipboard

<span class='text-positive'>不可信的来源</span>
hey, how are <strong>you</strong>?
7 minutes ago

Jane (可信的 name 但是不可信的 text)
doing fine, how r you?
4 minutes ago
I just feel like typing a really, really, <strong>REALLY</strong> long message to annoy you...
4 minutes ago

Jao (可信的)
Did it work?
1 minutes ago
版权声明 本中文文档内容版权为站长个人所有,保留所有权利。
免责声明 本站点所包含的任何跳转链接均为第三方广告内容,站点对这些广告内容的准确性、合法性、真实性不承担任何责任。用户点击跳转链接进入第三方网站后,应自行判断广告内容的真实性和合法性,并自行承担因使用广告内容而产生的风险和责任。任何因使用第三方广告内容而导致的损失或损害,本站点概不负责。