Skip to content
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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

eviIIt
Copy link
Contributor

@eviIIt eviIIt commented Aug 8, 2019

cd

Why

用户需求

image

Docs

新增的 keep-alive.md

@auto-badge auto-badge bot added the enhancement New feature or request label Aug 8, 2019
@eviIIt eviIIt marked this pull request as ready for review August 8, 2019 11:38
src/count-down.vue Show resolved Hide resolved
src/count-down.vue Outdated Show resolved Hide resolved
@@ -96,6 +103,19 @@ export default {
},
mounted() {
if (this.autoplay) this.start()
window.addEventListener('unload', this.setSession)
if (sessionStorage.getItem(this.keepInSession)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isAlive

@@ -96,6 +103,20 @@ export default {
},
mounted() {
if (this.autoplay) this.start()
window.addEventListener('unload', this.setSession)
let session = sessionStorage.getItem(this.keepInSession)
Copy link
Contributor

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 Show resolved Hide resolved
session = JSON.parse(session)
const mountTime = session.rafId
? Number(new Date()) - session.unloadTime
: 0
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接记startTime不就行了?不用又记unloadTime又记countdown吧

beforeDestroy() {
cancelAnimationFrame(this.rafId)
this.setSession()
window.removeEventListener('unload', this.setSession)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接在beforeDestroy里setSession就行了吧,为啥要listen unload呢?

@netlify
Copy link

netlify bot commented Aug 9, 2019

Deploy preview for femessage-count-down ready!

Built with commit 0810503

https://deploy-preview-4--femessage-count-down.netlify.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants