I am facing an issue with a method that is supposed to display a modal window 4 seconds after the user logs onto the website. If the modal is closed, it should not be displayed again for the next 24 hours. However, I am encountering problems with LocalStorage not storing the data and not returning the variable that holds the date. How can I resolve this issue?
mounted () {
this.runModalTimer()
this.setDevHoursModal()
},
methods: {
runModalTimer (): void {
setTimeout(() => {
this.isModalVisible = true
}, 4000)
},
setDevHoursModal (): boolean {
if (localStorage) {
let nextPopup = localStorage.getItem('isModalVisible')
if (nextPopup > new Date()) {
return this.isModalVisible = true
}
let expires = new Date()
expires = expires.setHours(expires.getHours() + 24)
localStorage.setItem('isModalVisible', expires)
}
}
}