我们在使用表格的时候,有时由于后端接口或者是网络慢等问题,会出现请求接口数据慢问题,这时我们就可以给表格<el-table>加个loading加载动画,接口请求成功之后再关闭loading动画效果。
ElementUI表格动画主要用到v-loading="loading"
1、首先在表格中加入属性:v-loading="loading"
<template> <div> <el-table :data="UserList" border stripe v-loading="loading"> <el-table-column label="ID" prop="id" min-width="20"></el-table-column> <el-table-column label="账号" prop="name"></el-table-column> <el-table-column label="姓名" prop="realname"></el-table-column> <el-table-column label="操作" width="180px"> <template slot-scope="scope"> <el-button type="primary" icon="el-icon-edit" size="mini"></el-button> <el-button type="danger" icon="el-icon-delete" size="mini"></el-button> </template> </el-table-column> </el-table> </div> </template>
2、在data定义默认值,加载成功之后关闭动画
<script> export default { data () { return { loading: true, } } //请求成功之后关闭加载动画 methods: { async getUserList () { const { data: res } = await this.$http.get('/admin/index', { params: this.queryInfo }) if (res.code != 200) { return this.$message.error('获取用户列表失败') } this.loading=false // console.log( res.data.current_page) this.UserList = res.data.data this.total = res.data.total this.queryInfo.pagenum = res.data.current_page }, created () { this.getUserList() }, methods: { async getUserList () { const { data: res } = await this.$http.get('/admin/index', { params: this.queryInfo }) if (res.code != 200) { return this.$message.error('获取用户列表失败') } this.loading=false this.UserList = res.data.data }, } </script>
文章评论(0)