mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 15:41:33 +00:00
Select multiple emails using checkboxes
This commit is contained in:
@@ -7,6 +7,9 @@ new Server({
|
|||||||
},
|
},
|
||||||
factories: {
|
factories: {
|
||||||
email: Factory.extend({
|
email: Factory.extend({
|
||||||
|
id(i) {
|
||||||
|
return i;
|
||||||
|
},
|
||||||
from(){
|
from(){
|
||||||
return faker.internet.email()
|
return faker.internet.email()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<table>
|
<table>
|
||||||
|
Number selected: {{selectedEmailIds.size}}
|
||||||
<thead>
|
<thead>
|
||||||
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="email in emails" :key="email.id" :class="[email.read ? 'read' : '']">
|
<tr v-for="email in emails" :key="email.id" :class="[email.read ? 'read' : '']">
|
||||||
<td><input type="checkbox" /></td>
|
<td><input type="checkbox"
|
||||||
|
:checked="selectedEmailIds.has(email.id)"
|
||||||
|
@click="addToSelectedEmails(email.id)" /></td>
|
||||||
<td>{{email.from}}</td>
|
<td>{{email.from}}</td>
|
||||||
<td>
|
<td>
|
||||||
<p><strong>{{email.subject}}</strong> - {{email.body}}</p>
|
<p><strong>{{email.subject}}</strong> - {{email.body}}</p>
|
||||||
@@ -18,9 +21,18 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
|
import { ref } from 'vue';
|
||||||
export default {
|
export default {
|
||||||
setup(){
|
setup(){
|
||||||
return {format}
|
let selectedEmailIds = ref(new Set(['1', '5']))
|
||||||
|
let addToSelectedEmails = (id) => {
|
||||||
|
if(selectedEmailIds.value.has(id)) {
|
||||||
|
selectedEmailIds.value.delete(id)
|
||||||
|
} else {
|
||||||
|
selectedEmailIds.value.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {format, selectedEmailIds, addToSelectedEmails}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
emails: {
|
emails: {
|
||||||
|
|||||||
Reference in New Issue
Block a user