-
Notifications
You must be signed in to change notification settings - Fork 22
Vue Composition API: Refs
Mike Lyttle edited this page May 9, 2023
·
1 revision
focusOnDate(date: DateWrapper): void {
const dateEpoch = date.fromEpoch();
const container = this.$refs[dateEpoch] as HTMLElement[];
container[0].querySelector("button")?.focus();
}
<div
v-for="dateGroup in dateGroups"
:key="dateGroup.key"
:ref="dateGroup.key"
>
</div>
import { ref } from "vue";
const dateRefs = ref(new Map<string, HTMLElement>());
function focusOnDate(date: DateWrapper): void {
const dateEpoch = date.fromEpoch();
const container = dateRefs.get(dateEpoch);
container?.querySelector("button")?.focus();
}
<div
v-for="dateGroup in dateGroups"
:key="dateGroup.key"
:ref="(el) => dateRefs.set(dateGroup.key, el)"
>
</div>
- This is a complicated example where we are storing a collection of references that we want to index by a key. A Map wouldn't be needed in other instances.
-
Developer Standard and Processes
-
Workstation Setup
-
IDE Configuration
-
Application Config
-
RedHat SSO Authorization Server
-
Known Issues