Skip to content

How to use the persist plugin with class based data contexts #4435

Closed Answered by DoubleREW
DoubleREW asked this question in 1. Help
Discussion options

You must be logged in to vote

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;
  }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by DoubleREW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant