You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.2 KiB

9 years ago
<script src="https://cdn.jsdelivr.net/lodash/4.10.0/lodash.min.js"></script>
<script src="../../dist/vue.min.js"></script>
9 years ago
<style>
.danger {
background-color: red;
}
</style>
9 years ago
<script type="text/x-template" id="t">
<div>
<h1>{{ total }} Components</h1>
9 years ago
<p>{{ action }} took {{time}}ms.</p>
<button @click="shuffle">shuffle</button>
<button @click="add">add</button>
<table class="table table-hover table-striped test-data">
<row v-for="item in items" track-by="id"
:class="{ danger: item.id === selected }"
:item="item"
@select="select(item)"
@remove="remove(item)">
</row>
</table>
</div>
9 years ago
</script>
9 years ago
<script type="text/x-template" id="row">
<tr>
<td class="col-md-1">{{item.id}}</td>
<td class="col-md-4">
<a @click="$emit('select')">{{item.label}}</a>
</td>
<td class="col-md-1">
<button @click="$emit('remove')">remove</button>
</td>
</tr>
9 years ago
</script>
<div id="el">
</div>
<script>
var total = 1000
9 years ago
var items = []
for (var i = 0; i < total; i++) {
9 years ago
items.push({
id: i,
label: String(Math.random()).slice(0, 5)
})
}
var s = window.performance.now()
console.profile('render')
9 years ago
var vm = new Vue({
el: '#el',
template: '#t',
data: {
total: total,
9 years ago
time: 0,
9 years ago
action: 'Render',
9 years ago
items: items,
selected: null
},
methods: {
9 years ago
shuffle: monitor('shuffle', function () {
9 years ago
this.items = _.shuffle(this.items)
}),
9 years ago
add: monitor('add', function () {
9 years ago
this.items.push({
id: total++,
9 years ago
label: String(Math.random()).slice(0, 5)
})
}),
9 years ago
select: monitor('select', function (item) {
9 years ago
this.selected = item.id
}),
9 years ago
remove: monitor('remove', function (item) {
9 years ago
this.items.$remove(item)
})
},
components: {
row: {
props: ['item'],
template: '#row'
}
}
})
setTimeout(function () {
vm.time = window.performance.now() - s
console.profileEnd('render')
9 years ago
}, 0)
9 years ago
function monitor (action, fn) {
9 years ago
return function () {
var s = window.performance.now()
fn.apply(this, arguments)
Vue.nextTick(function () {
9 years ago
vm.action = action
9 years ago
vm.time = window.performance.now() - s
})
}
}
</script>