If i used class A extends class B, when refresh page, class A will lose methods in class B #2596
-
i known the reason maybe is : prototype # demo
class A {
say() {
console.log('say')
}
}
export default defineStore('store', {
state: () => {
a : new A()
}
})
# than refresh page , if i do a.say() ==> undefined |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Mar 6, 2024
Replies: 1 comment 1 reply
-
You need to add a custom serialization mechanism for classes to work with SSR (or local storage if that's what you are using). I need to add a cookbook entry page in the docs based on one of my lessons in Mastering Pinia but it sums up to using payload plugins in nuxt or https://github.com/Rich-Harris/devalue to serialize/revive classes |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to add a custom serialization mechanism for classes to work with SSR (or local storage if that's what you are using). I need to add a cookbook entry page in the docs based on one of my lessons in Mastering Pinia but it sums up to using payload plugins in nuxt or https://github.com/Rich-Harris/devalue to serialize/revive classes