i want show unique date in message chat
Example.
data() {
return {
message: [
{id: 1,message: 'hi', created_at: '2023-02-16 00:44:41'},
{id: 2,message: 'how are you?', created_at: '2023-02-16 01:00:00'},
{id: 3,message: 'hello', created_at: '2023-03-01 12:00:00'},
{id: 5,message: 'hi', created_at: '2023-03-01 15:56:00'},
]
}}
2
Answers
You should format the date property.
You can create a function:
Then in your template when calling the date prop, you can send it as function property. For example:
You have to create an additional prop for your messages array, for example "show_date". This prop will determine whether to show the date or not.
You can do it by computed value:
Here is the func for check if dates are the same day, but you can use momentjs or dayjs instead
And finally, you have to render messages by the computed prop and display date only if ‘show_date’ is true.
You can find full code here: https://codepen.io/AlekseiKrivo/pen/xxyXpmY