0
0
Vueframework~5 mins

Dynamic attribute names in Vue - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does 'dynamic attribute names' mean in Vue?
It means you can set an attribute name on an element using a variable or expression, so the attribute changes based on your data.
Click to reveal answer
beginner
How do you bind a dynamic attribute name in Vue template?
Use the v-bind directive with square brackets around the attribute name, like <div v-bind:[attrName]="value">.
Click to reveal answer
intermediate
Why use dynamic attribute names in Vue?
To make your components flexible and reusable by changing attributes like id, class, or aria-label based on data or user input.
Click to reveal answer
beginner
Example: What does <button v-bind:[buttonType]="true"> do if buttonType = 'disabled'?
It adds the disabled attribute to the button, making it disabled because the attribute name is 'disabled' and its value is true.
Click to reveal answer
intermediate
Can dynamic attribute names be used with event listeners in Vue?
Yes, you can use v-on with dynamic event names like v-on:[eventName]="handler" to listen to different events based on data.
Click to reveal answer
How do you bind a dynamic attribute name in Vue?
Av-bind:[attributeName]
Bv-bind(attributeName)
C:attributeName
Dv-bind.attributeName
What happens if you write
and attr = 'title'?
AAn error occurs because attr is a string.
BThe div gets an attribute named 'attr' with value 'value'.
CThe div gets a title attribute with the value of 'value'.
DThe div gets no new attribute.
Can dynamic attribute names be used to set ARIA attributes in Vue?
AYes, to improve accessibility dynamically.
BNo, ARIA attributes must be static.
COnly for aria-label, not others.
DOnly in Vue 2, not Vue 3.
Which Vue directive allows dynamic event names?
Av-bind:[eventName]
Bv-on:[eventName]
Cv-event:[eventName]
Dv-model:[eventName]
What is the benefit of using dynamic attribute names in Vue?
AImproves CSS styling automatically.
BDisables reactivity for that attribute.
CPrevents all runtime errors.
DMakes components more flexible and reusable.
Explain how to use dynamic attribute names in Vue templates and why they are useful.
Think about how you can change attribute names based on data.
You got /4 concepts.
    Describe how dynamic attribute names can improve accessibility in Vue applications.
    Consider how accessibility attributes might change based on context.
    You got /4 concepts.