Menu
CoddyTech

Show without Unmounting

Part of the Fundamentals section of Coddy's Vue journey. Lesson 22 of 55.

Use v-show when hiding should keep an element mounted. This panel starts hidden, but its input still exists in the DOM.

const expanded = ref(false);
// <div v-show="expanded"><input aria-label="Memo"></div>

The directive toggles CSS display. Showing the panel again reuses the existing input, including text the user typed. Unlike v-if, it does not create an exclusive branch chain with v-else. Choose according to whether the hidden content should stay mounted.

challenge icon

Challenge

Easy

Keep a note panel div#result mounted but initially hidden using v-show. Button #toggle switches visibility. Inside it keep an ordinary unbound input#draft. Text typed there must survive hiding and showing the panel.

Try it yourself

<!doctype html><html><head><meta charset="UTF-8"><title>Vue practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals