-
Hi, I've tried to call the $persist magic function inside the constructor and inside the init method, but it fails to work. https://codepen.io/rewrew/pen/VwoNmpb?editors=1010 Is it possible to do this? Thanks a lot. |
Beta Was this translation helpful? Give feedback.
Answered by
DoubleREW
Nov 16, 2024
Replies: 1 comment
-
Found out myself, with the global Alpine.$persist we can init a public class property or we can do the same inside the constructor: class MyComponent {
counter = Alpine.$persist(0).as('MyComponent::counter');
constructor() {
// this.counter = Alpine.$persist(0).as('MyComponent::counter');
}
increment() {
this.counter += 1;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
DoubleREW
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found out myself, with the global Alpine.$persist we can init a public class property or we can do the same inside the constructor: