# HMR (热模块更新)
Pinia支持热模块更新,因此您可以直接在您的应用程序中修改您的stores并与它们进行交互,而无需重新加载页面,从而允许您保留现有的状态,添加,甚至删除state,actions,和getters。
目前,官方只支持Vite (opens new window),但任何执行import.meta.hot规范的打包器都应该能生效(webpack (opens new window)似乎使用import.meta.webpackHot而不是import.meta.hot)。您需要在任何store声明旁边添加这段代码。假设您有三个stores:auth.js, cart.js, 和chat.js, 您必须在创建store定义后添加(并调整)它:
// auth.js
import { defineStore, acceptHMRUpdate } from 'pinia'
const useAuth = defineStore('auth', {
// options...
})
// make sure to pass the right store definition, `useAuth` in this case.
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useAuth, import.meta.hot))
}
← 从Vuex≤4迁移 Testing(测试) →