相关疑难解决方法(0)

如何在vue组件中使用setInterval

我在每个my-progress中定义了计时器,用于更新视图的值,但控制台显示常量变化的值,并且视图的值仍未更改,我该如何在计时器中更改值观点

Vue.component('my-progress', {
    template: '\
            <div class="progress progress-bar-vertical" data-toggle="tooltip" data-placement="top">\
                <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" :style="{height: pgvalue}">{{pgvalue}}\
                </div>\
            </div>\
        ',
    data : function(){  

        return {
            pgvalue : '50%',
            intervalid1:'',
        }
    },
    computed:{

        changes : {
            get : function(){
                return this.pgvalue;
            },
            set : function(v){
                this.pgvalue =  v;
            }
        }
    },
    mounted : function(){

        this.todo()     
    },
    beforeDestroy () {

       clearInterval(this.intervalid1)
    },
    methods : {

        todo : function(){          
            this.intervalid1 = setInterval(function(){
                this.changes = ((Math.random() * 100).toFixed(2))+'%';
                console.log (this.changes);
            }, 3000);
        } …
Run Code Online (Sandbox Code Playgroud)

javascript vue-component vuejs2

28
推荐指数
2
解决办法
5万
查看次数

标签 统计

javascript ×1

vue-component ×1

vuejs2 ×1