🚀 Welcome to Hebilicious Snapshot Dom Nuxt Module!
Inspired by SvelteKit’s same feature.
Ephemeral DOM state — like scroll positions on sidebars, the content of elements and so on — is discarded when you navigate from one page to another.
For example, if the user fills out a form but clicks a link before submitting, then hits the browser’s back button, the values they filled in will be lost. In cases where it’s valuable to preserve that input, you can take a snapshot of DOM state, which can then be restored if the user navigates back.
Install this module from NPM :
npm i @hebilicious/snapshot-dom-nuxt-module
Add it to your nuxt.config.ts file:
export default defineNuxtConfig({
modules: [
"@hebilicious/snapshot-dom-nuxt-module"
]
})
<script setup lang="ts">
const comment = ref("") // This will be restored on nav and refresh
const another = ref("") // This will be restored on nav
const no = ref("") // This won't be
// auto imported
useSnapshot([
{ capture: comment, restore: (v) => { comment.value = v } },
{ capture: another, restore: (v) => { another.value = v }, persist: false }
])
</script>
<template>
<input v-model="comment" type="text">
<input v-model="another" type="text">
<input v-model="no" type="text">
</template>
JSON.stringify for the sessionStorage.Contributions, issues and feature requests are welcome!
Fork this repo
Install node and pnpm Use corepack enable && corepack prepare pnpm@latest --activate to install pnpm easily
Use pnpm i at the mono-repo root.
Make modifications and follow conventional commits.
Open a PR 🚀🚀🚀
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.