问题描述
在vue中,我有以下模板:
<i class="bar" :style="style">
<i class="dot"></i>
</i>
然后js中的代码如下:
props: {
progress: {
type: Number,
default: function () {
return 0;
}
},
userInfo: {
type: Object,
default: function () {
return {};
}
}
},
mounted() {
let self = this;
self.$nextTick(() => {
self.width = self.progress;
})
// setTimeout(() => {
// this.width = this.progress;
// })
},
computed: {
style() {
return {
width: this.width + '%',
}
}
},
bar的样式有一个宽度变化的动效:
transition: width 0.5s ease;
为什么我使用nextTick没有动效,而使用setTimeout有动效呢?
讲的挺详细