我在每个my-progress中都定义了timer,用来更新view的值,但是console显示的值一直在变化,而view的值还是没有变化,请问怎么才能在timer中改变这个值观点
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);
}
},
})
这是链接: jsbin.com/safolom
原文由 A_Wen 发布,翻译遵循 CC BY-SA 4.0 许可协议
this
没有指向 Vue。尝试或者
或者
请参阅 如何在回调中访问正确的
this
?