mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-24 07:55:34 +00:00
Video 2 - Create UI for table using Options API techniques
This commit is contained in:
31
src/App.vue
31
src/App.vue
@@ -1,13 +1,34 @@
|
|||||||
<template>
|
<template>
|
||||||
<h1>VMail Inbox</h1>
|
<h1>VMail Inbox</h1>
|
||||||
|
|
||||||
|
<table class="mail-table">
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="email in unarchivedEmails"
|
||||||
|
:key="email.id"
|
||||||
|
:class="['clickable', email.read ? 'read' : '']"
|
||||||
|
@click="email.read = true">
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" />
|
||||||
|
</td>
|
||||||
|
<td>{{email.from}}</td>
|
||||||
|
<td>
|
||||||
|
<p><strong>{{email.subject}}</strong> - {{email.body}}</p>
|
||||||
|
</td>
|
||||||
|
<td class="date">{{format(new Date(email.sentAt), 'MMM do yyyy')}}</td>
|
||||||
|
<td><button @click="email.archived = true">Archive</button></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
|
format,
|
||||||
"emails": [
|
"emails": [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
@@ -47,6 +68,16 @@ export default {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
sortedEmails() {
|
||||||
|
return this.emails.sort((e1, e2) => {
|
||||||
|
return e1.sentAt < e2.sentAt ? 1 : -1
|
||||||
|
})
|
||||||
|
},
|
||||||
|
unarchivedEmails() {
|
||||||
|
return this.sortedEmails.filter(e => !e.archived)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user