【发布时间】:2020-11-22 12:15:57
【问题描述】:
当值 - v-if 指令绑定到 - 从 true 更改为 false 时,我试图添加一些延迟来过渡到元素。我正在使用Vuex来维护isLoading的状态,以便在其他组件中使用。
所以我有一个 API 调用,在等待响应时将 this.$store.state.isLoading 设置为 true,一旦收到响应则设置为 false。但问题是 API 响应几乎是即时的,进度条只闪烁一瞬间。
<template>
<div>
<b-progress v-if="isLoading" :max="max">
<b-progress-bar :value="count"></b-progress-bar>
</b-progress>
</div>
</template>
<script>
module.exports = {
data() {
return {
count: 0,
max: 100
}
},
computed: {
isLoading () {
return this.$store.state.isLoading;
}
}
}
</script>
在状态改变后添加延迟是正确的想法吗?如果是这样,正确的做法是什么?
【问题讨论】: