how to use setInterval in vue component

前端 未结 2 754
有刺的猬
有刺的猬 2020-12-14 00:04

I define the timer in each my-progress, used to update the value of view, but the console shows the value of the constant changes, and the value of view is still not changed

2条回答
  •  眼角桃花
    2020-12-14 00:53

    check this example:

    Vue.component('my-progress-bar',{
    	template:
    `
    {{ percent }}%
    `, props: { percent: {default: 0} } }); new Vue({ el: '#app', data: {p: 50}, created: function() { var self = this; setInterval(function() { if (self.p<100) { self.p++; } }, 100); } });
    
    
    
    

提交回复
热议问题