加载 Loading
获取数据或加载中时显示,提示用户正在等待中。
基础用法
最简单的Loading
<template>
<div class="demo-loading">
<b-loading></b-loading>
</div>
</template>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
<template>
<div class="demo-loading">
<b-loading></b-loading>
</div>
</template>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
居中固定
可以在父级元素中居中固定 默认是剧中固定的,fix设置为false后用于加载类似下拉加载的功能
我是后面的段落我是后面的段落我是后面的段落我是后面的段落
<template>
<div class="demo-loading">
<div>我是后面的段落我是后面的段落我是后面的段落我是后面的段落</div>
<b-loading fix></b-loading>
</div>
</template>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
<template>
<div class="demo-loading">
<div>我是后面的段落我是后面的段落我是后面的段落我是后面的段落</div>
<b-loading fix></b-loading>
</div>
</template>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
自定义内容
可以自定义文字和内容
加载中
loading
loading
<template>
<div>
<div class="demo-loading">
<b-loading fix>加载中</b-loading>
</div>
<div class="demo-loading">
<b-loading fix show-text="loading"></b-loading>
</div>
<div class="demo-loading">
<b-loading fix show-text="loading" show-icon="loading2"></b-loading>
</div>
</div>
</template>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
<template>
<div>
<div class="demo-loading">
<b-loading fix>加载中</b-loading>
</div>
<div class="demo-loading">
<b-loading fix show-text="loading"></b-loading>
</div>
<div class="demo-loading">
<b-loading fix show-text="loading" show-icon="loading2"></b-loading>
</div>
</div>
</template>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
切换显示状态
切换显示状态
我是后面的段落我是后面的段落我是后面的段落我是后面的段落
<template>
<div>
<div class="demo-loading">
<div>我是后面的段落我是后面的段落我是后面的段落我是后面的段落</div>
<b-loading v-show="loading" fix></b-loading>
</div>
<div>
<b-button v-if="loading" type="danger" @click="loading = false">停止</b-button>
<b-button v-else @click="loading = true">加载</b-button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const loading = ref(false)
</script>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
<template>
<div>
<div class="demo-loading">
<div>我是后面的段落我是后面的段落我是后面的段落我是后面的段落</div>
<b-loading v-show="loading" fix></b-loading>
</div>
<div>
<b-button v-if="loading" type="danger" @click="loading = false">停止</b-button>
<b-button v-else @click="loading = true">加载</b-button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const loading = ref(false)
</script>
<style scoped>
.demo-loading {
position: relative;
overflow: hidden;
display: inline-block;
margin-right: 5px;
width: 200px;
height: 100px;
border-radius: 4px;
border: 1px solid #cecece;
}
</style>
Props
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
showIcon | 显示加载图标 | String | loading | — |
showText | 显示加载的文字 | String | loading | — |
fix | 是否固定于父级中心 | Boolean | — | true |
size | 文字显示的大小 | Number | — | — |