Vue.js course ยท Module 2: Template Syntax

Vue Directives

6 min read ยท
In this lesson4

Directives are special attributes starting with v-. Each directive is like an instruction for the Mars base control system.

The mustaches from the previous lesson have two gaps. They cannot reach attributes, so a sensor image URL or a disabled button cannot depend on the data. And they cannot hear the operator: clicking the hologram triggers nothing. Directives close both gaps. Their structure is always the same: a name after the v- prefix, an argument after a colon, modifiers after dots and an expression in quotes. In v-on:submit.prevent="onSubmit" the name is on, the argument is submit, the modifier is prevent, and the value is the onSubmit function.

v-bind - Attribute Binding

v-bind keeps an attribute in sync with the data: after the colon you give the attribute name, and in quotes an expression. Since this directive appears all the time, it has a shorthand - just the colon. Here is a panel template with four typical cases:

<template>
  <div class="control-panel" style="background: #0a0e27; padding: 1rem;">
    <!-- Full syntax -->
    <img v-bind:src="sensorImage" v-bind:alt="sensorName">

    <!-- Shorthand syntax (recommended) -->
    <img :src="sensorImage" :alt="sensorName">

    <!-- Dynamic attributes -->
    <a :href="documentationUrl" :class="linkClass">Documentation</a>

    <!-- Boolean attributes -->
    <button :disabled="isProcessing" class="btn-neon">Launch</button>
  </div>
</template>

Both images produce identical HTML - the shorthand changes nothing but the length of the code. The quotes hold an expression, not text: :alt="sensorName" inserts the variable's value, while a plain alt="sensorName" would write the word sensorName literally. The boolean attribute disabled appears when the value is truthy and disappears for false. When a binding evaluates to null or undefined, Vue removes the attribute entirely.

The data for these bindings are ordinary refs from the script section - nothing new compared with module 1:

<script setup>
import { ref } from 'vue'

const sensorImage = ref('/images/oxygen-sensor.png')
const sensorName = ref('Oxygen Sensor MK-7')
const documentationUrl = ref('https://nova-lab.mars/docs')
const linkClass = ref('neon-link')
const isProcessing = ref(false)
</script>

Setting isProcessing.value = true is enough for the button to get the disabled attribute - you do not touch the template. The button's look comes from ordinary CSS, because v-bind does not change how styles work:

<style>
.btn-neon {
  background: transparent;
  border: 2px solid #00ff88;
  color: #00ff88;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
.btn-neon:hover {
  background: #00ff8822;
  box-shadow: 0 0 10px #00ff88;
}
</style>

There is not a single Vue feature in the style section. My advice: always write the : shorthand - in a dense template you immediately see which attributes are alive. Since Vue 3.4 an even shorter form works: when the attribute and the variable share a name, :id means the same as :id="id".

v-on - Event Handling

v-on attaches a function to a browser event; its shorthand is the at sign @. The value can be a function name or a short statement, for example a call with an argument. The special $event variable passes the event object when you call the function yourself:

<template>
  <div class="reactor-controls" style="background: #0a0e27; color: #00b4d8;">
    <!-- Full syntax -->
    <button v-on:click="handleActivation">Activate</button>

    <!-- Shorthand syntax (recommended) -->
    <button @click="handleActivation" class="btn-reactor">Activate Reactor</button>

    <!-- Inline handler -->
    <button @click="powerLevel++">Increase Power</button>

    <!-- With argument -->
    <button @click="sendSignal('ALPHA-BASE')">Send Signal</button>

    <!-- With event object -->
    <button @click="handleActivation($event)">Event Info</button>
  </div>
</template>

The compiler recognizes what you gave it: the bare name handleActivation means Vue calls the function and passes the native event as its only argument. A form with parentheses is a statement, so the event has to be passed explicitly through $event. There is no .value in powerLevel++, because refs are unwrapped in the template.

The handler functions live in the script, where .value applies again:

<script setup>
import { ref } from 'vue'

const powerLevel = ref(0)

function handleActivation(event) {
  console.log('Reactor activated!', event)
}

function sendSignal(baseCode) {
  alert(`Sending signal to: ${baseCode}`)
}
</script>

The button is still an ordinary <button> - v-on only adds an event listener to it, just as addEventListener would.

Event Modifiers

Calls like event.preventDefault() or event.stopPropagation() clutter functions with DOM details. A modifier added after a dot takes care of that in the template. The cheat sheet below shows only the opening tags:

<template>
  <div class="mission-control">
    <!-- Prevent default -->
    <form @submit.prevent="onSubmit" class="mission-form">

    <!-- Stop propagation -->
    <div @click.stop="onClick" class="stop-zone">

    <!-- Only once -->
    <button @click.once="launchSequence" class="btn-launch">Start Sequence</button>

    <!-- Capture mode -->
    <div @click.capture="onCapture" class="capture-zone">

    <!-- Self only -->
    <div @click.self="onSelf" class="self-zone">

    <!-- Combination -->
    <a @click.stop.prevent="onClick" class="safe-link">
  </div>
</template>

.prevent calls event.preventDefault(), so the form does not reload the page. .stop calls event.stopPropagation(), and the event does not reach the parents. .once lets the handler fire at most once, .capture handles the event in the capture phase, before it reaches the child, and .self reacts only when the element itself was clicked. When the event arrives, Vue applies the modifiers first and only then calls your function. In a chain the order matters: @click.prevent.self blocks the default action for the children too, while @click.self.prevent does it only for the element itself.

Key Modifiers

The keyup and keydown events have modifiers too. Vue knows the aliases .enter, .tab, .delete (Delete and Backspace), .esc, .space and the arrows, and the system keys are .ctrl, .alt, .shift and .meta. The functions in the example are defined in the script:

<template>
  <input @keyup.enter="sendCommand" placeholder="Command for the station">
  <input @keyup.esc="clearCommand" placeholder="Esc clears the field">
  <button @click.ctrl="emergencyStop">Ctrl + click: emergency stop</button>
</template>

sendCommand runs only after Enter, clearCommand only after Escape, and the emergency stop requires Ctrl to be held down. Other keys trigger nothing - without a single if checking event.key. In the next lesson you will see that :class and :style are special kinds of v-bind that accept objects and arrays.

Remember: the colon connects an attribute to data, the at sign connects an event to a function, and the dot adds a safety protocol to the command.

Code for this lesson: App.vue
<script setup>
import { ref } from 'vue'

const stationStatus = ref('operational')
const powerLevel = ref(85)
const alertLevel = ref('low')
const showDetails = ref(false)
const logoUrl = ref('https://placehold.co/100/00ff88/0a0e27?text=NOVA')

const systemMessages = ref([
  { id: 1, text: 'Life support systems: ONLINE', type: 'success' },
  { id: 2, text: 'Energy level: STABLE', type: 'info' },
  { id: 3, text: 'Communication with Earth: ACTIVE', type: 'success' }
])

function toggleDetails() {
  showDetails.value = !showDetails.value
}

function increasePower() {
  if (powerLevel.value < 100) {
    powerLevel.value += 5
  }
}

function decreasePower() {
  if (powerLevel.value > 0) {
    powerLevel.value -= 5
  }
}
</script>

<template>
  <div class="control-panel">
    <div class="station-header">
      <!-- v-bind for src and alt attributes -->
      <img :src="logoUrl" :alt="'NOVA LAB Logo'" class="logo">
      <h1>NOVA Research Station</h1>
    </div>

    <div class="power-control">
      <h2>Energy Control</h2>
      <!-- v-bind for class and style -->
      <div
        class="power-bar"
        :class="{ 'critical': powerLevel < 30, 'optimal': powerLevel >= 70 }"
        :style="{ width: powerLevel + '%' }"
      >
        {{ powerLevel }}%
      </div>

      <!-- v-on (@) for event handling -->
      <div class="controls">
        <button @click="decreasePower" class="btn btn-danger">-5%</button>
        <button @click="increasePower" class="btn btn-success">+5%</button>
      </div>
    </div>

    <div class="status-section">
      <h2>Systems Status</h2>
      <button @click="toggleDetails" class="btn btn-info">
        {{ showDetails ? 'Hide details' : 'Show details' }}
      </button>

      <div v-show="showDetails" class="messages">
        <div
          v-for="msg in systemMessages"
          :key="msg.id"
          :class="['message', 'message-' + msg.type]"
        >
          {{ msg.text }}
        </div>
      </div>
    </div>

    <div class="info-box">
      <h3>Vue.js directives</h3>
      <ul>
        <li><strong>v-bind</strong> (shorthand :) - attribute binding</li>
        <li><strong>v-on</strong> (shorthand @) - event handling</li>
        <li><strong>:class</strong> - dynamic CSS classes</li>
        <li><strong>:style</strong> - dynamic inline styles</li>
      </ul>
    </div>
  </div>
</template>

<style scoped>
.control-panel {
  background: linear-gradient(135deg, #0a0e27 0%, #1a1e3f 100%);
  min-height: 100vh;
  padding: 2rem;
  color: #ffffff;
  font-family: 'Courier New', monospace;
}

.station-header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 3px solid #00ff88;
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

h1, h2, h3 {
  color: #00ff88;
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

.power-control {
  background: rgba(0, 255, 136, 0.1);
  border: 2px solid #00ff88;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.power-bar {
  height: 40px;
  background: linear-gradient(90deg, #00ff88, #00b4d8);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  transition: all 0.3s ease;
  margin: 1rem 0;
}

.power-bar.critical {
  background: linear-gradient(90deg, #ff0055, #ff6600);
  animation: pulse 1s infinite;
}

.power-bar.optimal {
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.8);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 5px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'Courier New', monospace;
}

.btn-success {
  background: #00ff88;
  color: #0a0e27;
}

.btn-danger {
  background: #ff0055;
  color: #ffffff;
}

.btn-info {
  background: #00b4d8;
  color: #ffffff;
}

.btn:hover {
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(0, 255, 136, 0.4);
}

.status-section {
  background: rgba(0, 180, 216, 0.1);
  border: 2px solid #00b4d8;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.messages {
  margin-top: 1rem;
}

.message {
  padding: 1rem;
  margin: 0.5rem 0;
  border-radius: 5px;
  border-left: 4px solid;
}

.message-success {
  background: rgba(0, 255, 136, 0.2);
  border-color: #00ff88;
}

.message-info {
  background: rgba(0, 180, 216, 0.2);
  border-color: #00b4d8;
}

.info-box {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid #00ff88;
  border-radius: 10px;
  padding: 1.5rem;
}

.info-box ul {
  list-style: none;
  padding: 0;
}

.info-box li {
  padding: 0.5rem 0;
  color: #ffffff;
}

.info-box strong {
  color: #00b4d8;
}
</style>

The second editor is a modifiers lab: submit its form with .prevent, click the buttons with .stop and .once, and try Enter, Escape and the Ctrl+S shortcut in the text fields.

Code for this lesson: App.vue
<script setup>
import { ref } from 'vue'

const commandInput = ref('')
const searchQuery = ref('')
const formData = ref({
  mission: '',
  priority: 'medium',
  description: ''
})

const logs = ref([])
const systemMessages = ref([
  { id: 1, text: 'System initialized' },
  { id: 2, text: 'Connection established with Mars Base' },
  { id: 3, text: 'All systems operational' }
])
let nextMessageId = 4

function handleCommand(event) {
  event.preventDefault()
  if (commandInput.value.trim()) {
    logs.value.unshift({
      id: Date.now(),
      command: commandInput.value,
      timestamp: new Date().toLocaleTimeString()
    })
    commandInput.value = ''
  }
}

function preventRefresh(event) {
  event.preventDefault()
  alert('Form was stopped by event.preventDefault()')
}

function stopPropagation(event) {
  event.stopPropagation()
  systemMessages.value.unshift({ id: nextMessageId++, text: 'Clicked button - propagation stopped' })
}

function handleContainerClick() {
  systemMessages.value.unshift({ id: nextMessageId++, text: 'Container clicked' })
}

function runOnce() {
  systemMessages.value.unshift({ id: nextMessageId++, text: 'This handler runs only once!' })
}

function handleEnter() {
  systemMessages.value.unshift({ id: nextMessageId++, text: `Search executed: ${searchQuery.value}` })
  searchQuery.value = ''
}

function handleEscape() {
  searchQuery.value = ''
  systemMessages.value.unshift({ id: nextMessageId++, text: 'Search cleared with ESC' })
}

function handleCtrlS(event) {
  event.preventDefault()
  systemMessages.value.unshift({ id: nextMessageId++, text: 'Mission saved (Ctrl+S)' })
}

function submitMission(event) {
  event.preventDefault()
  logs.value.unshift({
    id: Date.now(),
    command: `Mission: ${formData.value.mission} | Priority: ${formData.value.priority}`,
    timestamp: new Date().toLocaleTimeString()
  })
  formData.value.mission = ''
  formData.value.description = ''
}
</script>

<template>
  <div class="modifiers-lab">
    <h1>Modifiers Laboratory - NOVA LAB</h1>

    <!-- Event Modifiers Section -->
    <section class="lab-section">
      <h2>Event Modifiers</h2>

      <!-- .prevent modifier -->
      <div class="demo-card">
        <h3>.prevent - Preventing default action</h3>
        <form @submit.prevent="preventRefresh" class="demo-form">
          <input
            type="text"
            placeholder="This form will not refresh the page"
            class="input-field"
          >
          <button type="submit" class="btn btn-primary">
            Submit (preventDefault)
          </button>
        </form>
        <code class="code-hint">@submit.prevent="preventRefresh"</code>
      </div>

      <!-- .stop modifier -->
      <div class="demo-card">
        <h3>.stop - Stopping event propagation</h3>
        <div @click="handleContainerClick" class="click-container">
          Click the container (event propagates)
          <button @click.stop="stopPropagation" class="btn btn-warning">
            Click the button (stop propagation)
          </button>
        </div>
        <code class="code-hint">@click.stop="stopPropagation"</code>
      </div>

      <!-- .once modifier -->
      <div class="demo-card">
        <h3>.once - Handler runs only once</h3>
        <button @click.once="runOnce" class="btn btn-success">
          Click me (works only once)
        </button>
        <code class="code-hint">@click.once="runOnce"</code>
      </div>

      <!-- Multiple modifiers -->
      <div class="demo-card">
        <h3>Combining modifiers</h3>
        <form @submit.prevent.stop="handleCommand" class="demo-form">
          <input
            v-model="commandInput"
            type="text"
            placeholder="Enter command..."
            class="input-field"
          >
          <button type="submit" class="btn btn-primary">
            Execute Command
          </button>
        </form>
        <code class="code-hint">@submit.prevent.stop="handleCommand"</code>
      </div>
    </section>

    <!-- Key Modifiers Section -->
    <section class="lab-section">
      <h2>Key Modifiers</h2>

      <!-- .enter modifier -->
      <div class="demo-card">
        <h3>.enter - Detects the Enter key</h3>
        <input
          v-model="searchQuery"
          @keyup.enter="handleEnter"
          type="text"
          placeholder="Type and press Enter..."
          class="input-field"
        >
        <code class="code-hint">@keyup.enter="handleEnter"</code>
      </div>

      <!-- .esc modifier -->
      <div class="demo-card">
        <h3>.esc - Detects the Escape key</h3>
        <input
          v-model="searchQuery"
          @keyup.esc="handleEscape"
          type="text"
          placeholder="Type and press ESC to clear..."
          class="input-field"
        >
        <code class="code-hint">@keyup.esc="handleEscape"</code>
      </div>

      <!-- System modifier keys -->
      <div class="demo-card">
        <h3>.ctrl + key - Key combinations</h3>
        <textarea
          v-model="formData.description"
          @keydown.ctrl.s="handleCtrlS"
          placeholder="Press Ctrl+S to save..."
          class="textarea-field"
          rows="4"
        ></textarea>
        <code class="code-hint">@keydown.ctrl.s="handleCtrlS"</code>
      </div>

      <!-- Multiple key modifiers -->
      <div class="demo-card">
        <h3>Complete form with modifiers</h3>
        <form @submit.prevent="submitMission" class="mission-form">
          <input
            v-model="formData.mission"
            type="text"
            placeholder="Mission name (Enter to submit)..."
            class="input-field"
          >
          <select v-model="formData.priority" class="select-field">
            <option value="low">Low Priority</option>
            <option value="medium">Medium Priority</option>
            <option value="high">High Priority</option>
          </select>
          <button type="submit" class="btn btn-primary">
            Submit Mission
          </button>
        </form>
      </div>
    </section>

    <!-- System Messages -->
    <section class="lab-section">
      <h2>System Messages</h2>
      <div class="messages-container">
        <div
          v-for="msg in systemMessages.slice(0, 10)"
          :key="msg.id"
          class="message-item"
        >
          <span class="message-time">{{ new Date().toLocaleTimeString() }}</span>
          <span class="message-text">{{ msg.text }}</span>
        </div>
      </div>
    </section>

    <!-- Command Logs -->
    <section class="lab-section" v-if="logs.length > 0">
      <h2>Command Logs</h2>
      <div class="logs-container">
        <div
          v-for="log in logs"
          :key="log.id"
          class="log-item"
        >
          <span class="log-time">{{ log.timestamp }}</span>
          <span class="log-command">{{ log.command }}</span>
        </div>
      </div>
    </section>

    <!-- Info Box -->
    <div class="info-box">
      <h3>Event & Key Modifiers in Vue</h3>
      <div class="info-grid">
        <div>
          <h4>Event Modifiers:</h4>
          <ul>
            <li><strong>.prevent</strong> - event.preventDefault()</li>
            <li><strong>.stop</strong> - event.stopPropagation()</li>
            <li><strong>.once</strong> - handler only once</li>
            <li><strong>.capture</strong> - capture mode</li>
            <li><strong>.self</strong> - only if target === currentTarget</li>
            <li><strong>.passive</strong> - { passive: true }</li>
          </ul>
        </div>
        <div>
          <h4>Key Modifiers:</h4>
          <ul>
            <li><strong>.enter</strong> - Enter key</li>
            <li><strong>.tab</strong> - Tab key</li>
            <li><strong>.delete</strong> - Delete/Backspace</li>
            <li><strong>.esc</strong> - Escape key</li>
            <li><strong>.space</strong> - Space key</li>
            <li><strong>.up/.down/.left/.right</strong> - Arrow keys</li>
            <li><strong>.ctrl/.alt/.shift/.meta</strong> - System keys</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.modifiers-lab {
  background: linear-gradient(135deg, #0a0e27 0%, #1a1e3f 100%);
  min-height: 100vh;
  padding: 2rem;
  color: #ffffff;
  font-family: 'Courier New', monospace;
}

h1 {
  text-align: center;
  color: #00ff88;
  text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
  margin-bottom: 3rem;
}

h2 {
  color: #00b4d8;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid #00b4d8;
  padding-bottom: 0.5rem;
}

h3 {
  color: #00ff88;
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.lab-section {
  background: rgba(0, 255, 136, 0.05);
  border: 2px solid #00ff88;
  border-radius: 10px;
  padding: 2rem;
  margin-bottom: 2rem;
}

.demo-card {
  background: rgba(0, 180, 216, 0.1);
  border: 2px solid #00b4d8;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.demo-form {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.mission-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-field, .select-field, .textarea-field {
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid #00b4d8;
  border-radius: 5px;
  padding: 0.75rem;
  color: #ffffff;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  flex: 1;
  min-width: 200px;
}

.input-field:focus, .select-field:focus, .textarea-field:focus {
  outline: none;
  border-color: #00ff88;
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.3);
}

.input-field::placeholder, .textarea-field::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 5px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'Courier New', monospace;
}

.btn-primary {
  background: #00ff88;
  color: #0a0e27;
}

.btn-warning {
  background: #ffb400;
  color: #0a0e27;
}

.btn-success {
  background: #00b4d8;
  color: #ffffff;
}

.btn:hover {
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(0, 255, 136, 0.4);
}

.click-container {
  background: rgba(255, 180, 0, 0.1);
  border: 2px dashed #ffb400;
  border-radius: 5px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 1rem;
}

.click-container:hover {
  background: rgba(255, 180, 0, 0.2);
}

.code-hint {
  display: block;
  background: rgba(0, 0, 0, 0.5);
  border-left: 4px solid #00ff88;
  padding: 0.75rem;
  border-radius: 5px;
  color: #00ff88;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
}

.messages-container, .logs-container {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.message-item, .log-item {
  padding: 0.75rem;
  background: rgba(0, 180, 216, 0.1);
  border-left: 4px solid #00b4d8;
  border-radius: 5px;
  margin-bottom: 0.5rem;
  display: flex;
  gap: 1rem;
  align-items: center;
}

.message-time, .log-time {
  color: #ffb400;
  font-size: 0.9rem;
  min-width: 100px;
}

.message-text, .log-command {
  color: #ffffff;
  flex: 1;
}

.info-box {
  background: rgba(0, 255, 136, 0.05);
  border: 2px solid #00ff88;
  border-radius: 10px;
  padding: 2rem;
}

.info-box h3 {
  margin-top: 0;
  margin-bottom: 1.5rem;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.info-box h4 {
  color: #00b4d8;
  margin-bottom: 1rem;
}

.info-box ul {
  list-style: none;
  padding: 0;
}

.info-box li {
  padding: 0.5rem 0;
  color: #ffffff;
  border-left: 3px solid #00b4d8;
  padding-left: 1rem;
  margin: 0.5rem 0;
}

.info-box strong {
  color: #00ff88;
}
</style>

Docs entries used in this lesson

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What is the v-bind directive used for?

  2. 2. What is the shorthand for v-bind:href?

  3. 3. What is v-on used for?

  4. 4. What does <img :src> without a value mean when a src variable exists in <script setup>?

  5. 5. What does .prevent do in @submit.prevent?

  6. 6. What does the .stop modifier do in v-on?

Hands-on tasks in the game

  • Code editor

    Use v-bind (shorthand :) to assign dynamic src, alt, href, and disabled attributes.

  • Click in order

    Arrange the click handling syntax with an argument:

  • Code editor

    Use v-on (or its @ shorthand) to handle the click, submit and keyup events.

  • Horizontal ordering

    Arrange the correct v-bind syntax for a dynamic src attribute:

  • Horizontal ordering

    Arrange the correct v-on syntax for handling a click:

  • Vertical ordering

    Order the steps of handling a click event in Vue:

  • Code editor

    Use the .prevent, .stop, and .once modifiers in event handling.

  1. QuestionPurpose of v-bind
  2. Questionv-bind Shorthand
  3. Coding taskPractice: v-bind for Attributes
  4. QuestionPurpose of v-on
  5. Click in orderv-on Syntax with Argument
  6. Coding taskPractice: v-on Event Handling
  7. QuestionSame-name Shorthand :attr (Vue 3.4+)
  8. QuestionThe .prevent Modifier
  9. QuestionThe .stop Modifier
  10. Put in orderv-bind Syntax with Attribute
  11. Put in orderv-on Syntax with Method
  12. Put in orderEvent Handling Process in Vue
  13. Coding taskPractice: Event Modifiers

Useful articles