<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Florin Codreanu on Medium]]></title>
        <description><![CDATA[Stories by Florin Codreanu on Medium]]></description>
        <link>https://medium.com/@florin.codreanu?source=rss-41d540a09f5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jZ7Oul4maIdqn4Lg.</url>
            <title>Stories by Florin Codreanu on Medium</title>
            <link>https://medium.com/@florin.codreanu?source=rss-41d540a09f5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 08:03:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@florin.codreanu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Vue.js v-if: the Joyful Guide From Basics to Senior-Level Subtleties]]></title>
            <link>https://medium.com/@florin.codreanu/vue-js-v-if-the-joyful-senior-guide-from-basics-to-senior-level-subtleties-87fc84638caa?source=rss-41d540a09f5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/87fc84638caa</guid>
            <dc:creator><![CDATA[Florin Codreanu]]></dc:creator>
            <pubDate>Fri, 31 Oct 2025 13:21:45 GMT</pubDate>
            <atom:updated>2025-10-31T13:29:08.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EydtOryGAJgCP_-fjbjuxw.jpeg" /></figure><p>This is a love letter to v-if. People think it’s a little “show/hide” switch. It’s not. It’s a gatekeeper of existence. It literally decides what lives in your DOM, what code even runs, and when something is allowed to be real. That’s beautiful. Let’s talk about it.</p><ol><li><strong>What </strong><strong>v-if actually does (and why it feels like creation magic)</strong></li></ol><p>v-if says: if this condition is true, bring this part of the template to life. If it’s false, don’t even bother rendering it.</p><pre>&lt;p v-if=&quot;isLoggedIn&quot;&gt;Welcome back!&lt;/p&gt;<br>&lt;p v-else&gt;Please sign in.&lt;/p&gt;</pre><p>Here’s the subtle part: if the condition becomes false later, Vue doesn’t just hide the element. It <em>removes it from the DOM</em>. Gone. Deleted. Soul released into the universe.</p><p>That means:</p><ul><li>The component and its children are destroyed.</li><li>Local state is lost.</li><li>The next time it shows up, mounted() runs again like a phoenix reborn.</li></ul><p>This is powerful. But it also means you can’t assume state “will still be there” after you toggle it.</p><p><strong>2. v-if vs </strong><strong>v-show</strong></p><p>v-show keeps the element in the DOM forever, but toggles CSS (display: none).<br> v-if actually mounts / unmounts.</p><p>Rule of thumb:</p><ul><li>If you rarely need something and it’s heavy: use v-if so you don’t even render it yet.</li><li>If you toggle constantly (tabs, dropdown, tooltip spam): use v-show for instant response.</li></ul><p>Think of it like this:</p><ul><li>v-show: “I’m still here, just closing my eyes.”</li><li>v-if: “Call me when you really need me. Until then I do not exist.”</li></ul><p><strong>3. v-if with </strong><strong>v-for: order matters and can ruin your evening</strong></p><pre>&lt;li v-for=&quot;user in users&quot; v-if=&quot;user.isActive&quot;&gt;{{ user.name }}&lt;/li&gt;</pre><p>Looks cute. But Vue runs v-for first, then tests v-if per item. That means it still spins through <em>every</em> user, creates all those sub-instances, and then filters. That’s waste. Also it can mess with keys and patching. Better patterns:</p><pre>&lt;li v-for=&quot;user in activeUsers&quot; :key=&quot;user.id&quot;&gt;<br>  {{ user.name }}<br>&lt;/li&gt;</pre><p>…where activeUsers is already filtered in a computed property.</p><p><strong>4. v-if on a </strong><strong>&lt;template&gt; = clean DOM, happy future you</strong></p><p>When you do:</p><pre>&lt;template v-if=&quot;showInfo&quot;&gt;<br>  &lt;p&gt;Hello!&lt;/p&gt;<br>  &lt;p&gt;More details here...&lt;/p&gt;<br>&lt;/template&gt;</pre><p>Vue doesn’t render a &lt;template&gt; tag. It just conditionally injects the contents. This lets you turn whole groups of elements on/off without wrapping them in an extra &lt;div class=&quot;because-frontend&quot;&gt;.</p><p>This keeps DOM clean, CSS simpler, and future-you less grumpy.</p><p><strong>5. Reusing component instances (the </strong><strong>:key trick that saves your sanity)</strong></p><p>Vue tries to be smart and reuse components between v-if / v-else. Sometimes that’s great. Sometimes it’s chaos.</p><pre>&lt;MyForm v-if=&quot;isLogin&quot; /&gt;<br>&lt;MyForm v-else /&gt;</pre><p>Both branches use &lt;MyForm&gt;, so Vue may reuse the same instance. Translation: state from the login form can “leak” into the register form. 👻</p><p>Fix it like this:</p><pre>&lt;MyForm v-if=&quot;isLogin&quot; key=&quot;login&quot; /&gt;<br>&lt;MyForm v-else key=&quot;register&quot; /&gt;</pre><p>Now Vue treats them as different lives, not one reincarnated in weird ways. This is one of those bugs that makes juniors say “Vue is broken” and seniors whisper “…no, we are.”</p><p><strong>6. </strong><strong>v-if as a lazy-loading gate (only load heavy stuff when the universe truly needs it)</strong></p><p>You can combine v-if with async components and &lt;Suspense&gt; to avoid loading expensive components at initial page load:</p><pre>&lt;Suspense&gt;<br>  &lt;template v-if=&quot;shouldLoadChart&quot;&gt;<br>    &lt;LazyChart /&gt;<br>  &lt;/template&gt;<br>&lt;/Suspense&gt;</pre><p>This means: we don’t even <em>import</em> LazyChart code until we actually need it. Your initial bundle is lighter, app loads faster, users smile, you feel like a performance wizard.</p><p>Most teams talk about “lazy loading.” Fewer wire it beautifully into v-if.</p><p><strong>7. DOM timing &amp; </strong><strong>nextTick(): “it’s gone”… “no, wait… now it’s gone”</strong></p><p>When a reactive value that controls v-if flips to false, Vue doesn’t instantly rip the DOM out in the same JavaScript microsecond. DOM updates are batched. So immediately after setting showModal.value = false, the element might still physically exist in the DOM until the next tick.</p><pre>watch(showModal, async (val) =&gt; {<br>  if (!val) {<br>    await nextTick()<br>    console.log(&#39;Now the modal is really gone from the DOM.&#39;)<br>  }<br>})</pre><p>This matters if you’re trying to, for example, return focus to a button only after the modal truly unmounted. This is one of those “why is my focus trap still active?!” puzzles.</p><p><strong>8. </strong><strong>v-if can intentionally <em>stop</em> reactivity in part of your app</strong></p><p>This is huge in real apps.</p><p>If you wrap something in v-if=&quot;isOpen&quot;, and isOpen is false, that subtree just doesn’t exist. Which means:</p><ul><li>No watchers there.</li><li>No computed properties there.</li><li>No effects.</li><li>No emits from that component.</li><li>Zero CPU cost from it.</li></ul><p>That’s not just hiding UI. That’s <em>turning off a world</em>.</p><pre>&lt;UserSidebar v-if=&quot;selectedUser&quot; :user=&quot;selectedUser&quot; /&gt;<br>&lt;UserMainPanel :user=&quot;selectedUser&quot; /&gt;</pre><p>If selectedUser becomes null, &lt;UserSidebar&gt; unmounts. All of its watchers and side effects vanish. But &lt;UserMainPanel&gt; is still there. If &lt;UserMainPanel&gt; was secretly expecting the sidebar to emit something… surprise, that emission no longer exists.</p><p>So v-if doesn’t just control visuals. It controls side-effect networks. Pay attention to that.</p><p><strong>9. Access control: </strong><strong>v-if on the child is cute, but too late</strong></p><pre>&lt;ParentLayout&gt;<br>  &lt;SecretPanel v-if=&quot;canSeeSecret&quot; /&gt;<br>&lt;/ParentLayout&gt;</pre><p>They think that means the user “can’t access” the secret logic. But ParentLayout <em>still mounts</em>, runs data fetching, maybe loads confidential data, etc.</p><p>If you want real access control / isolation / don’t-even-run-the-code energy, you gate higher:</p><pre>&lt;template v-if=&quot;userHasAccess&quot;&gt;<br>  &lt;ParentLayout /&gt;<br>&lt;/template&gt;<br><br>&lt;template v-else&gt;<br>  &lt;AccessDenied /&gt;<br>&lt;/template&gt;</pre><p>That way, the protected branch never mounts at all. It never breathes.</p><p><strong>10. Transitions + </strong><strong>v-if: the element lingers like a goodbye hug</strong></p><p>When you wrap a v-if block in a &lt;transition&gt;, Vue doesn’t instantly unmount the element. It first applies leave classes, lets the animation play, and <em>only then</em> destroys it.</p><pre>&lt;transition name=&quot;fade&quot;&gt;<br>  &lt;div v-if=&quot;showAlert&quot; class=&quot;alert&quot;&gt;Warning!&lt;/div&gt;<br>&lt;/transition&gt;</pre><p>So showAlert = false does not mean “it’s instantly gone.” It means “it’s fading out dramatically.” During that fade, it’s still technically clickable unless you disable interaction.</p><p>This is why sometimes users manage to click a button in a modal you “closed,” and you scream into a pillow.</p><p><strong>11. </strong><strong>v-if vs </strong><strong>v-show in huge lists: performance is not a religion, it’s situational</strong></p><p>People repeat:</p><ul><li>“v-if for rare toggles, v-show for frequent toggles.&quot;<br> Yes. But in big lists you need more nuance.</li></ul><p>Scenario A: You have 2000 rows, and most of them are basically never shown. Rendering them all and just hiding them with v-show is wasteful. Use v-if (or better: pre-filter and only iterate the ones that matter).</p><p>Scenario B: You have 4 tab panels with forms, and the user jumps between them quickly. Destroying and remounting forms with v-if means losing input state and re-running fetches. Use v-show so they’re all mounted once and then just shown/hidden instantly.</p><p>So yeah, the “rule” is true, but the senior truth is: the right answer depends on usage pattern, not dogma.</p><p><strong>12. SSR / hydration: client-only stuff needs a gentle entrance</strong></p><p>On the server, Vue runs v-if using server-side data and sends HTML to the browser. Then on the client, Vue “hydrates” that HTML and wires up reactivity.</p><p>If, in the browser, the v-if condition is different (for example it depends on window.innerWidth or localStorage which don’t exist on the server), Vue can complain and even re-render that section.</p><p>A safe pattern is: don’t render browser-only stuff until you’re actually in the browser.</p><pre>const isReadyOnClient = ref(false)<br><br>onMounted(() =&gt; {<br>  isReadyOnClient.value = true<br>})</pre><pre>&lt;div v-if=&quot;isReadyOnClient&quot;&gt;<br>  &lt;!-- content that depends on browser APIs --&gt;<br>&lt;/div&gt;</pre><p>Hydration mismatch avoided. Your server-render stays clean. Your client logic waits its turn. Harmony.</p><p><strong>13. Never do heavy logic inline in your </strong><strong>v-if</strong></p><pre>&lt;div v-if=&quot;expensiveCheck(user)&quot;&gt;<br>  ...<br>&lt;/div&gt;</pre><p>If expensiveCheck() scans a big array or does complicated checks, that work may run on every relevant reactive update. Not just once. Repeatedly. Silently.</p><p>Senior version:</p><pre>const isUserVisible = computed(() =&gt; expensiveCheck(user.value))</pre><pre>&lt;div v-if=&quot;isUserVisible&quot;&gt;<br>  ...<br>&lt;/div&gt;</pre><p>Now Vue caches it reactively. Fewer wasted cycles. Happier laptop fans.</p><p><strong>14. </strong><strong>v-if as a lazy fetch barrier</strong></p><p>Picture this: a child component does</p><pre>onMounted(() =&gt; {<br>  fetchData()<br>})</pre><p>If you render that component with v-show, it’ll mount immediately and fetchData() will run immediately, even if it’s “hidden.”</p><p>But if you render it with v-if=&quot;panelActive&quot;, the component doesn’t mount until the panel is actually opened by the user. Which means fetchData() only runs when it’s truly needed.</p><p>This is an elegant way to avoid hammering the backend for stuff the user might never even open.<br> Lots of mid-level folks know “lazy load,” but they don’t always connect that directly to v-if controlling lifecycle.</p><p>Closing thought (and it’s a happy one)</p><p>v-if isn’t just a conditional. It’s lifecycle control. It decides:</p><ul><li>who exists,</li><li>when they get to run code,</li><li>when they’re cleaned up,</li><li>whether state survives,</li><li>how much work the browser does,</li><li>if hydration stays calm,</li><li>and whether your UI feels instant or sluggish.</li></ul><p>Junior devs think v-if is about “show or hide.”<br> Senior devs know it’s about resource management, timing, data safety, and user happiness.</p><p>And honestly? I love that. I love that a tiny directive can express “not yet, little component, the world’s not ready for you” — and then, at the perfect moment: “okay, now live.”</p><p>That’s the job. We build little worlds, we let them exist just when they’re needed, and we try to leave both the UI and the humans using it a tiny bit happier. 🌼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87fc84638caa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting alias ‘@’ on Quasar CLI with Vite]]></title>
            <link>https://medium.com/@florin.codreanu/setting-alias-on-quasar-cli-with-vite-dbcce7e93f76?source=rss-41d540a09f5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbcce7e93f76</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[quasar]]></category>
            <category><![CDATA[vitejs]]></category>
            <dc:creator><![CDATA[Florin Codreanu]]></dc:creator>
            <pubDate>Sun, 13 Aug 2023 07:08:34 GMT</pubDate>
            <atom:updated>2023-08-13T07:14:30.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*oBnZIRvEV6fBVPr-1LDSGg.jpeg" /></figure><p>Quasar is a fantastic cross-platform Vuejs framework, you can get more details at <a href="https://quasar.dev/">https://quasar.dev/</a></p><p>Using Quasar CLI with Vite you will be in the peculiarity that you will not have the classic vite.config.js file, instead, for configuration you will have the file <strong>quasar.config.js </strong>file<strong> (</strong>more details here<strong> </strong><a href="https://quasar.dev/quasar-cli-vite/quasar-config-file">https://quasar.dev/quasar-cli-vite/quasar-config-file</a>). A common problem on the forums refers to setting an alias to the src folder (I mean the classical problem: <strong>alias src to @ not working</strong>)</p><p>To solve the problem you need to edit <strong>quasar.config.js</strong>, where you will find the parameter extendViteConf, most likely commented. To point the alias ‘@’ to the src path, uncomment and make it look like below:</p><pre>extendViteConf (viteConf, { isServer, isClient }) {<br>  Object.assign(viteConf.resolve.alias, {<br>    &quot;@&quot;: path.join(__dirname, &#39;./src&#39;)<br>  })<br>}</pre><p>Greetings, from my first and small article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbcce7e93f76" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>