Setting the file. One moment.
Subchapter 5.1
references/advanced-hmr.mdMarkdown1 KBView on GitHub
Pinia supports HMR to edit stores without page reload, preserving existing state.
Add this snippet after each store definition:
import { defineStore, acceptHMRUpdate } from 'pinia'
export const useAuth = defineStore('auth', {
// store options...
})
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useAuth, import.meta.hot))
}import { defineStore, acceptHMRUpdate } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
const increment = () => count.value++
return { count, increment }
})
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useCounterStore, import.meta.hot))
}import.meta.hotimport.meta.webpackHotimport.meta.hot spec should workWith @pinia/nuxt, acceptHMRUpdate is auto-imported but you still need to add the HMR snippet manually.