Last active
May 17, 2018 02:18
-
-
Save allenfantasy/fed8446e5bf2758c02b71fe52c864a6e to your computer and use it in GitHub Desktop.
Performance difference between render and non-render for vue list component
This file contains 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
<template> | |
<div class="item">{{ number }}</div> | |
</template> | |
<script> | |
export default { | |
name: 'TestItem', | |
props: { | |
number: Number | |
} | |
} | |
</script> |
This file contains 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
<template> | |
<div class="item-list"> | |
<item v-if="show" v-for="number in 10000" :key="number" :number="number"></item> | |
</div> | |
</template> | |
<script> | |
import Item from './item' | |
export default { | |
name: 'TestItemList', | |
components: { | |
Item | |
}, | |
props: { | |
show: { | |
type: Boolean, | |
default: false | |
} | |
}, | |
} | |
</script> |
This file contains 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
import Item from './item' | |
export default { | |
name: 'TestItemNewList', | |
components: { | |
Item | |
}, | |
props: { | |
show: { | |
type: Boolean, | |
default: false | |
} | |
}, | |
data () { | |
return { | |
numbers: Array.from({ length: 10000 }).map((i, index) => index + 1) | |
} | |
}, | |
render (h) { | |
if (this.show) { | |
return <div class="item-list"> | |
{ this.numbers.map(number => <item number={ number } key={ number }></item>) } | |
</div> | |
} else { | |
return null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
renderedItemList.js
userender
function to render a large amount of item list, whileitemList
simply render every item via<item>
component.There's a big perf difference between these two implementations, I would put some stats on later.