-
So I have something like this <template x-for="item in items">
<a :x-ref="`menu-${item.id}`" x-text="item.label" :href="item.href" @mouseenter="active = item.id"></a>
</template> init() {
this.$nextTick(() => {
this.$watch('active', (value) => {
if (value !== null) {
this.$refs[`menu-${value}`].focus();
}
});
});
} But when I hover the menu item, it gives me this error. Which means that the $watch run before it renders, or am I missing something? |
Beta Was this translation helpful? Give feedback.
Answered by
SimoTod
Nov 2, 2021
Replies: 1 comment 1 reply
-
You can't have dynamic ref in Alpine v3. See #1527 (comment) <template x-for="item in items">
<a :id="`menu-${item.id}`" x-text="item.label" :href="item.href" @mouseenter="active = item.id"></a>
</template> init() {
this.$nextTick(() => {
this.$watch('active', (value) => {
if (value !== null) {
document.getElementById(`menu-${value}`).focus();
}
});
});
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
itsfaqih
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't have dynamic ref in Alpine v3. See #1527 (comment)
You'll need to use something different, for example