Variable storage method

// sessionStorage
// Appropriate for data that needs to be retained only during the current session, like temporary form data and unfinished operation states.

  
myVariable: string;

  constructor() {
    const storedValue = sessionStorage.getItem('myVariable');
    if (storedValue) {
      this.myVariable = storedValue;
    } else {
      this.myVariable = '默认值';
    }
  }

  saveVariable() {
    sessionStorage.setItem('myVariable', this.myVariable);
  }

Last updated

Was this helpful?