[Vuejs]-How to display a popup only once per day vue

1👍

In your setDevHoursModal method, you’re not always returning a value. You could resolve this by just returning the result of the condition:

setDevHoursModal(): boolean {
  if (localStorage) {
    let nextPopup = localStorage.getItem('isModalVisible');
    if (nextPopup > new Date()) {
      return (this.isModalVisible = true);  // let's be a little more explicit here
    }

    let expires = new Date();
    expires = expires.setHours(expires.getHours() + 24);

    localStorage.setItem('isModalVisible', expires);
    return false;
  }
  return true;
}

Leave a comment