vue上传文件时 怎么搞个转圈的样子让用户等待不能进行其他操作?
在Vue中,你可以使用v-if和v-show指令来控制一个加载动画的显示和隐藏,从而阻止用户进行其他操作。以下是一个简单的示例:
<template>
<div>
<!-- 上传按钮 -->
<input type="file" @change="uploadFile" />
<!-- 加载动画组件 -->
<div v-show="isLoading" class="loading">
<!-- 这里放置你的加载动画样式 -->
<div class="spinner"></div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
isLoading: false // 控制加载动画的显示和隐藏
};
},
methods: {
uploadFile(event) {
// 显示加载动画
this.isLoading = true;
// 模拟上传文件的异步操作
setTimeout(() => {
// 文件上传完成后隐藏加载动画
this.isLoading = false;
}, 3000);
}
}
};
</script>
<style>
.loading {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
}
.spinner {
/* 这里放置你的加载动画样式 */
}
</style>
在上述示例中,当用户选择文件后,uploadFile方法会被调用,该方法会在开始上传文件时将isLoading设置为true,显示加载动画;在上传完成后,将isLoading设置为false,隐藏加载动画。用户在加载动画显示期间无法进行其他操作。你可以根据自己的需求修改加载动画的样式。
原文地址: https://www.cveoy.top/t/topic/jcu8 著作权归作者所有。请勿转载和采集!