Moved "number selected"... but it doesn't update. Why?

This commit is contained in:
Jeffrey Biles
2020-03-17 22:24:08 -07:00
parent e5b83a407a
commit 92c429407e
3 changed files with 8 additions and 6 deletions

View File

@@ -1,18 +1,23 @@
<template> <template>
<h1>VMail Inbox</h1> <h1>VMail Inbox</h1>
Number selected: {{selectedEmailIds.size}}
<MailTable :emails="emails" /> <MailTable :emails="emails" />
</template> </template>
<script> <script>
import MailTable from '@/components/MailTable.vue'; import MailTable from '@/components/MailTable.vue';
import { ref } from 'vue'; import useEmailSelection from '../composition/useEmailSelection';
export default { export default {
async setup(props, {attrs, slots}){ async setup(props, {attrs, slots}){
let response = await fetch('/api/emails'); let response = await fetch('/api/emails');
let {emails} = await response.json(); let {emails} = await response.json();
return {emails} let {selectedEmailIds} = useEmailSelection();
return {emails, selectedEmailIds}
}, },
components: { components: {
MailTable MailTable

View File

@@ -1,9 +1,5 @@
<template> <template>
<table> <table>
Number selected: {{selectedEmailIds.size}}
<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> <td>

View File

@@ -2,6 +2,7 @@ import { ref } from 'vue';
export const useEmailSelection = function(){ export const useEmailSelection = function(){
let selectedEmailIds = ref(new Set(['1', '5'])) let selectedEmailIds = ref(new Set(['1', '5']))
let toggleEmailSelection = (id) => { let toggleEmailSelection = (id) => {
if(selectedEmailIds.value.has(id)) { if(selectedEmailIds.value.has(id)) {
selectedEmailIds.value.delete(id) selectedEmailIds.value.delete(id)