Skip to content

Instantly share code, notes, and snippets.

@allenfantasy
Last active May 17, 2018 02:18
Show Gist options
  • Save allenfantasy/fed8446e5bf2758c02b71fe52c864a6e to your computer and use it in GitHub Desktop.
Save allenfantasy/fed8446e5bf2758c02b71fe52c864a6e to your computer and use it in GitHub Desktop.
Performance difference between render and non-render for vue list component
<template>
<div class="item">{{ number }}</div>
</template>
<script>
export default {
name: 'TestItem',
props: {
number: Number
}
}
</script>
<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>
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
}
}
}
@allenfantasy
Copy link
Author

renderedItemList.js use render function to render a large amount of item list, while itemList simply render every item via <item> component.

There's a big perf difference between these two implementations, I would put some stats on later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment