Created
July 8, 2020 10:38
-
-
Save ihpr/3c46223ca7d2313b8fef7662c5cfcf44 to your computer and use it in GitHub Desktop.
Vue mixin to create deferred components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function (count = 10) { | |
return { | |
data () { | |
return { | |
displayPriority: 0, | |
} | |
}, | |
mounted () { | |
this.runDisplayPriority() | |
}, | |
methods: { | |
runDisplayPriority () { | |
const step = () => { | |
requestAnimationFrame(() => { | |
this.displayPriority++; | |
if (this.displayPriority < count) { | |
step() | |
} | |
}) | |
}; | |
step() | |
}, | |
defer (priority) { | |
return this.displayPriority >= priority | |
}, | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment