Number selected: {{emailSelection.ids.size}}
Number selected: {{emailSelection.ids.size}}
+| + :checked="emailSelection.ids.has(email.id)" + @click="emailSelection.toggle(email.id)" /> | {{email.from}} | @@ -23,8 +25,8 @@ export default { setup(){ - let {selectedEmailIds, toggleEmailSelection} = useEmailSelection(); - return {format, selectedEmailIds, toggleEmailSelection} + let {emailSelection} = useEmailSelection(); + return {format, emailSelection,} }, props: { emails: { diff --git a/src/composition/useEmailSelection.js b/src/composition/useEmailSelection.js index f5f46ee..0689e08 100644 --- a/src/composition/useEmailSelection.js +++ b/src/composition/useEmailSelection.js @@ -1,19 +1,21 @@ -import { ref } from 'vue'; +import { ref, reactive } from 'vue'; +let ids = new Set(['1', '5']); export const useEmailSelection = function(){ - let selectedEmailIds = ref(new Set(['1', '5'])) - let toggleEmailSelection = (id) => { - if(selectedEmailIds.value.has(id)) { - selectedEmailIds.value.delete(id) - } else { - selectedEmailIds.value.add(id); + let emailSelection = reactive({ + ids: ids, + toggle: function(id) { + if(this.ids.has(id)) { + this.ids.delete(id) + } else { + this.ids.add(id); + } } - } + }) return { - selectedEmailIds, - toggleEmailSelection + emailSelection, } } |