element/examples/docs/zh-CN/loading.md

186 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<style>
.demo-loading .el-table {
border: none;
}
</style>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}],
loading: true,
loading2: true,
fullscreenLoading: false
}
},
methods: {
openFullScreen() {
this.fullscreenLoading = true;
setTimeout(() => {
this.fullscreenLoading = false;
}, 3000);
}
}
}
</script>
## Loading 加载
加载数据时显示动效。
### 区域加载
在表格等容器中加载数据时显示。
:::demo 在 Loading 组件中Element 准备了自定义命令`v-loading`,只需要绑定`Boolean`即可。默认状况下Loading 遮罩会插入到绑定元素的子节点,通过添加`body`修饰符,可以使遮罩插入至 DOM 中的 body 上。
```html
<template>
<el-table
v-loading.body="loading"
:data="tableData"
style="width: 100%">
<el-table-column
prop="date"
label="日期"
width="180">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="180">
</el-table-column>
<el-table-column
prop="address"
label="地址">
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}],
loading: true
};
}
};
</script>
```
:::
### 加载文案
可自定义加载文案。
:::demo 在绑定了`v-loading`指令的元素上添加`element-loading-text`属性,其值会被渲染为加载文案,并显示在加载图标的下方。
```html
<template>
<el-table
v-loading="loading2"
element-loading-text="拼命加载中"
:data="tableData"
style="width: 100%">
<el-table-column
prop="date"
label="日期"
width="180">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
width="180">
</el-table-column>
<el-table-column
prop="address"
label="地址">
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}],
loading2: true
};
}
};
</script>
```
:::
### 整页加载
页面数据加载时显示。
:::demo 当需要全屏遮罩时,可使用`fullscreen`修饰符(此时遮罩会插入至 body 上)。此时若需要锁定屏幕的滚动,可以使用`lock`修饰符。
```html
<template>
<el-button
type="primary"
@click.native="openFullScreen"
v-loading.fullscreen.lock="fullscreenLoading">
显示整页加载3 秒后消失
</el-button>
</template>
<script>
export default {
data() {
return {
fullscreenLoading: false
}
},
methods: {
openFullScreen() {
this.fullscreenLoading = true;
setTimeout(() => {
this.fullscreenLoading = false;
}, 3000);
}
}
}
</script>
```
:::