The All-In-One Component

This second episode will present the simplest way to implement the version banner feature in a single component. The question becomes: are you confident enough with this version?

2 min read
Share
The All-In-One Component

Code

👉 VersionBanner01.vue

Version 1: Initial Implementation

The first principle is to use Nuxt 4 layers folder to encapsulate the feature.

<script lang="ts" setup>
// File: layers/version-01/components/VersionBanner01.vue
const VERSION_KEY = "app-version";
const isVisible = ref(false);
// ⓘ useRuntimeConfig() retrieves variables from nuxt.config.ts
const version = useRuntimeConfig().public.version;
const close = () => {
  isVisible.value = false;
  localStorage.setItem(VERSION_KEY, version);
};
onMounted(() => {
  if (localStorage.getItem(VERSION_KEY) !== version) {
    isVisible.value = true;
  }
});
</script>

<template>
  <div v-if="isVisible">
    New Version {{ version }}
    <button @click="close">Close</button>
  </div>
</template>

Issues with this Implementation

Next Step

If you are confident with this single component, well, it is okay. If not, you might follow the rest of the journey to improve our design.

Specifications v2.1

Let’s add the new specifications to have a better design:

Decision Map

Let’s take a look at the current map (Open 🔎):

Decision Map Graph

Previous

Next