// Vue 3 示例代码:使用 loading 组件
<template>
<div>
<button @click="toggleLoading">Toggle Loading</button>
<div v-if="isLoading" class="loading-overlay">
<p>Loading...</p>
</div>
</div>
</template>
<script>
export default {
data() {
return {
isLoading: false,
};
},
methods: {
toggleLoading() {
this.isLoading = !this.isLoading;
},
},
};
</script>
<style scoped>
.loading-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
color: white;
}
</style>
模板部分 (<template>
):
toggleLoading
方法。v-if
指令来控制 loading-overlay
的显示和隐藏,当 isLoading
为 true
时显示。脚本部分 (<script>
):
data
函数,返回一个包含 isLoading
属性的对象,初始值为 false
。methods
对象,包含 toggleLoading
方法,用于切换 isLoading
的布尔值。样式部分 (<style scoped>
):
.loading-overlay
类的样式,使其覆盖整个页面,并居中显示加载文本。rgba
设置背景颜色为半透明黑色,使加载层看起来更美观。上一篇:vue上传文件到后端
下一篇:vue3生成二维码
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站