0
0
Vueframework~20 mins

Attribute binding with v-bind in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Attribute Binding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered output of this Vue template?

Consider the following Vue component template using v-bind for attribute binding:

<template>
  <button v-bind:disabled="isDisabled">Click Me</button>
</template>

<script setup>
import { ref } from 'vue'
const isDisabled = ref(true)
</script>

What will the button look like in the browser?

Vue
<template>
  <button v-bind:disabled="isDisabled">Click Me</button>
</template>

<script setup>
import { ref } from 'vue'
const isDisabled = ref(true)
</script>
AThe button is hidden from the page.
BThe button is disabled and cannot be clicked.
CThe button is visible but has no text.
DThe button is enabled and clickable.
Attempts:
2 left
💡 Hint

Think about what the disabled attribute does when set to true.

📝 Syntax
intermediate
2:00remaining
Which option correctly binds the href attribute in Vue?

You want to bind a dynamic URL to an anchor tag's href attribute using Vue's v-bind. Which of the following is syntactically correct?

A<a v-bind:href="url">Link</a>
B<a v-bind(href)="url">Link</a>
C<a :href=url>Link</a>
D<a v-bind:href=url>Link</a>
Attempts:
2 left
💡 Hint

Remember the correct syntax for v-bind with attribute names and values.

🔧 Debug
advanced
2:00remaining
Why does this attribute binding not update dynamically?

Given this Vue component snippet:

<template>
  <img v-bind:src="imageSrc" alt="Image"/>
</template>

<script setup>
const imageSrc = './img1.png'

setTimeout(() => {
  imageSrc = './img2.png'
}, 2000)
</script>

Why does the image not change after 2 seconds?

Vue
<template>
  <img v-bind:src="imageSrc" alt="Image"/>
</template>

<script setup>
const imageSrc = './img1.png'

setTimeout(() => {
  imageSrc = './img2.png'
}, 2000)
</script>
ABecause the setTimeout function is not allowed inside <code>&lt;script setup&gt;</code>.
BBecause the <code>v-bind</code> directive does not work with <code>src</code> attributes.
CBecause imageSrc is not reactive; it should be a ref to update dynamically.
DBecause the image path './img2.png' is invalid and cannot load.
Attempts:
2 left
💡 Hint

Think about how Vue tracks changes to variables to update the DOM.

state_output
advanced
2:00remaining
What is the value of the title attribute after clicking the button?

Examine this Vue component:

<template>
  <button v-bind:title="tooltip" @click="changeTooltip">Hover me</button>
</template>

<script setup>
import { ref } from 'vue'
const tooltip = ref('Initial tip')
function changeTooltip() {
  tooltip.value = 'Updated tip'
}
</script>

After clicking the button once, what is the title attribute shown on hover?

Vue
<template>
  <button v-bind:title="tooltip" @click="changeTooltip">Hover me</button>
</template>

<script setup>
import { ref } from 'vue'
const tooltip = ref('Initial tip')
function changeTooltip() {
  tooltip.value = 'Updated tip'
}
</script>
ANo title attribute is present
BInitial tip
CAn empty string
DUpdated tip
Attempts:
2 left
💡 Hint

Consider how reactive variables update bound attributes on events.

🧠 Conceptual
expert
3:00remaining
Which option best explains why v-bind is preferred over string interpolation for binding attributes?

In Vue, you can bind attributes using v-bind or by using string interpolation inside attribute values. For example:

<img v-bind:src="imageUrl" />
<img src="{{ imageUrl }}" />

Why is v-bind the preferred method for binding attributes?

A<code>v-bind</code> ensures the attribute updates reactively and handles special attributes correctly, while string interpolation inside attributes does not update reactively and can cause invalid HTML.
B<code>v-bind</code> only works with event handlers, not attributes, so string interpolation is needed for attributes.
CString interpolation is faster and more efficient, but <code>v-bind</code> is easier to write.
DString interpolation automatically escapes HTML, while <code>v-bind</code> does not, making string interpolation safer.
Attempts:
2 left
💡 Hint

Think about how Vue updates the DOM when data changes and how attributes behave.