目标:
热更新 pinia ,在修改 store 之后无需刷新也米娜就可以预览数据更新。
参考:
也就是说在使用 vite 时候在 store 添加该内容就可以实现该需求
// auth.js
import { defineStore, acceptHMRUpdate } from 'pinia'
export 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))
}
在 webpack 使用 import.meta.webpackHot