数据代理
本章目标
<template>
<div>
<div>
<!-- 省略查询html代码 -->
</div>
<el-table
:data="tableList.data"
>
<!-- 省略代码 -->
</el-table>
<el-pagination
@size-change="onSizeChange"
@current-change="onCurrentChange"
:current-page="tableList.pagination.curr"
:page-sizes="[5, 10, 20 ,30]"
:page-size="tableList.pagination.limit"
:total="tableList.pagination.total"
layout="total, sizes, prev, pager, next, jumper"
></el-pagination>
</div>
</template>
<script lang='ts'>
import { Component, Vue } from "vue-property-decorator";
import { mixinDataStore } from "@/mixin/view/Store";
import { Action } from "vuex-class";
@Component({
name: "GridDemo",
mixins: [mixinDataStore]
})
export default class GridDemo extends Vue {
// 定义在vuex中的请求数据函数,只要返回的是Promise类型即可
@Action("list") gridList: any;
// 预留配置-列表配置
// 列表代理对象
tableList: any = {
// 列表数据源
data: [],
// 代理配置
proxy: {
// 请求数据函数
requestFun: this.gridList,
// 分页每页显示条数字段名称,默认为limit,此参数传递到服务端
limitParam: "pageSize",
// 分页页码字段名称,默认为page,此参数传递到服务端
pageParam: "current",
// 初始化后自动加载数据
autoLoad: true,
// 读取数据相关配置
reader: {
// 数据根节点
rootProperty: "data.data.records",
successProperty: "data.code",
totalProperty: "data.data.total",
messageProperty: "data.data.msg"
}
}
};
}
</script>具体实现
扩展模块结构设计
挂载代理
预留扩展
整体结构

填充代码
入口模块
promise代理入口模块
promise.classic代理
promise.modern代理
使用时二次扩展
mixin类
结语
最后更新于