Skip to content

Instantly share code, notes, and snippets.

@iggyster
Created July 8, 2020 10:38
Show Gist options
  • Save iggyster/3c46223ca7d2313b8fef7662c5cfcf44 to your computer and use it in GitHub Desktop.
Save iggyster/3c46223ca7d2313b8fef7662c5cfcf44 to your computer and use it in GitHub Desktop.
Vue mixin to create deferred components
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