-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 添加刷新倒计时记录不丢失 #4
base: dev
Are you sure you want to change the base?
Conversation
src/count-down.vue
Outdated
@@ -96,6 +103,19 @@ export default { | |||
}, | |||
mounted() { | |||
if (this.autoplay) this.start() | |||
window.addEventListener('unload', this.setSession) | |||
if (sessionStorage.getItem(this.keepInSession)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isAlive
src/count-down.vue
Outdated
@@ -96,6 +103,20 @@ export default { | |||
}, | |||
mounted() { | |||
if (this.autoplay) this.start() | |||
window.addEventListener('unload', this.setSession) | |||
let session = sessionStorage.getItem(this.keepInSession) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
先判断this.keepInSession
为true再去getItem吧
src/count-down.vue
Outdated
session = JSON.parse(session) | ||
const mountTime = session.rafId | ||
? Number(new Date()) - session.unloadTime | ||
: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
记rafId有啥用
const mountTime = session.rafId | ||
? Number(new Date()) - session.unloadTime | ||
: 0 | ||
this.elapsed = this.time - (session.countdown - mountTime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接记startTime不就行了?不用又记unloadTime又记countdown吧
src/count-down.vue
Outdated
beforeDestroy() { | ||
cancelAnimationFrame(this.rafId) | ||
this.setSession() | ||
window.removeEventListener('unload', this.setSession) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接在beforeDestroy里setSession就行了吧,为啥要listen unload呢?
Deploy preview for femessage-count-down ready! Built with commit 0810503 |
Why
用户需求
Docs
新增的 keep-alive.md