Vue - Nuxt
Difference between β vs !==?
π§© 1οΈβ£ != vs !== (JavaScript β not Vue specific)
!= vs !== (JavaScript β not Vue specific)These are comparison operators, but they behave slightly differently.
==
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:
.preventmeans β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:
.stopmeans β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