Last active
April 2, 2017 01:15
-
-
Save kitak/3d9e8fc11237338b685331ec1bff49ae to your computer and use it in GitHub Desktop.
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
var Item = Vue.extend({ | |
data: function () { | |
return { | |
id: 0, | |
message: '' | |
}; | |
}, | |
template: '<li :data-id="id">{{ message }}</li>' | |
}); | |
var demo = new Vue({ | |
el: '#demo', | |
data: { | |
title: 'items', | |
items: [] | |
}, | |
mounted: function () { | |
Vue.nextTick(() => { | |
var start = 0; | |
var now = 0; | |
setInterval(() => { | |
now += 1; | |
var item; | |
var diff = 0; | |
if (this.items.length > 15) { | |
diff = this.items.length - 15; | |
var clone = this.$refs.wrapper.children[0].cloneNode(true); | |
for (var i = 0; i < diff; i++) { | |
var child = clone.removeChild(clone.children[0]); | |
child.textContent = now; | |
clone.appendChild(child); | |
} | |
console.log(clone); | |
this.$refs.wrapper.replaceChild(clone, this.$refs.wrapper.children[0]); | |
} else { | |
var li = document.createElement('li'); | |
li.textContent = now; | |
this.$refs.wrapper.children[0].appendChild(li); | |
this.items.push(now); | |
} | |
}, 1000); | |
}); | |
} | |
}) |
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
<div id="demo" v-cloak> | |
<div ref="wrapper"> | |
<ul> | |
</ul> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment