vue2 + antd能否在遮罩上显示进度条
是的,Vue2和Ant Design都可以在遮罩上显示进度条。
首先,你需要引入Ant Design的进度条组件,可以使用<a-progress>组件。然后在需要显示进度条的地方,使用<a-spin>组件作为遮罩,并在其中嵌套<a-progress>组件。
下面是一个简单的示例代码:
<template>
<div>
<a-button @click="startLoading">开始加载</a-button>
<a-spin :spinning="loading">
<a-progress :percent="percent" :status="status"></a-progress>
</a-spin>
</div>
</template>
<script>
export default {
data() {
return {
loading: false,
percent: 0,
status: "active"
};
},
methods: {
startLoading() {
this.loading = true;
this.status = "active";
this.percent = 0;
const interval = setInterval(() => {
this.percent += 10;
if (this.percent >= 100) {
clearInterval(interval);
this.loading = false;
this.status = "success";
}
}, 1000);
}
}
};
</script>
在上面的示例中,点击"开始加载"按钮会触发startLoading方法,该方法会将loading设置为true,然后通过setInterval定时增加percent的值,当percent达到100时,清除定时器,并将loading设置为false,将status设置为"success",这样进度条会显示加载完成的状态。
注意:以上只是一个简单的示例,实际使用时,你可能需要根据具体需求进行调整
原文地址: https://www.cveoy.top/t/topic/iYKg 著作权归作者所有。请勿转载和采集!