1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <div id="app"> <div class="content" v-html="show_content"></div> </div> <script src="https://cdn.hongfs.cn/ajax/libs/vue/2.6.10/vue.min.js"></script> <script> new Vue({ el: '#app', data: { content: [ '中国的目标从来不是超越美国,', '而是不断超越自我,', '成为更好的中国。', ], show_content: '', }, mounted () { this.handleStartShowContent(); }, methods: { handleStartShowContent () { const len = this.content.join('').length;
var i = 0;
const t = setInterval(() => { i++;
this.show_content = this.handleGetContent(i);
len <= i && clearInterval(t); }, 100); }, handleGetContent (len) { var value = '';
this.content.map(item => { if (len <= 0) return;
value += item.length <= len ? item + '<br/>' : item.substring(0, len);
len -= item.length; });
return value; }, }, }); </script>
|