Vue - Nuxt

Difference between β‰  vs !==?

🧩 1️⃣ != vs !== (JavaScript β€” not Vue specific)

These are comparison operators, but they behave slightly differently.

Operator
Meaning
Type Check
Example
Result

==

Equal to (loose)

❌ No

"5" == 5

βœ… true

!=

Not equal (loose)

❌ No

"5" != 5

❌ false

===

Equal to (strict)

βœ… Yes

"5" === 5

❌ false

!==

Not equal (strict)

βœ… Yes

"5" !== 5

βœ… true

πŸ’‘ Rule of thumb: πŸ‘‰ Always use the strict ones (=== and !==) β€” they avoid weird bugs.

Example in Vue:

<div v-if="userAge !== 18">
  You are not 18.
</div>

βœ… This checks both value and type strictly.

Why submit.prevent?Why we use prevent.default?

πŸ‘‡ Example:

<form @submit.prevent="handleSubmit">
  <button type="submit">Submit</button>
</form>

Normally, when a form submits, the browser reloads the page (the default HTML behavior). But in Vue (and most modern web apps), we don’t want that β€” we handle submission ourselves (via JS).

πŸ’‘ So:

  • .prevent means β€œprevent the default browser action.”

πŸ‘‰ Think of it as:

β€œDon’t refresh the page, I’ll handle it with Vue instead.”

Why use click.stop? What is the use case of stop ?

πŸ‘‡ Example:

<div @click="outerClick">
  <button @click.stop="innerClick">Click Me</button>
</div>

Without .stop: When you click the button β†’ Vue runs both innerClick() and outerClick() (Because the click β€œbubbles up” to the parent div.)

With .stop: The event stops there β€” only innerClick() runs.

πŸ’‘ So:

  • .stop means β€œstop the event from bubbling up to parent elements.”

πŸ‘‰ Think of it as:

β€œOnly this element should react to the click β€” not its parents.”

Dynamic Slots? #dynamicSlot

Slots let you pass custom content from parent to child. A dynamic slot means the slot name itself is dynamic (changes at runtime).


🎯 Example:

🧱 Child.vue

<template>
  <div>
    <slot name="header">Default Header</slot>
    <slot name="footer">Default Footer</slot>
  </div>
</template>

🧩 Parent.vue

<script setup>
import Child from "./Child.vue";
const slotName = "header"; // could change dynamically
</script>

<template>
  <Child>
    <template v-slot:[slotName]>
      <h1>This goes into the header slot</h1>
    </template>
  </Child>
</template>

πŸ’‘ Here, v-slot:[slotName] means:

β€œBind to the slot whose name is in the variable slotName.”

So if slotName = 'header', β†’ the content goes into <slot name="header">.

If later slotName = 'footer', β†’ it’ll go into <slot name="footer"> dynamically.

Last updated