Files
vxe-table/examples/views/table/grid/Page.vue
xuliangzhan 0d3e5b33de 更新文档
2019-12-30 20:13:33 +08:00

154 lines
4.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div>
<p class="tip">
数据代理通过配置 <grid-api-link prop="proxy-config"/> 启用数据代理将不需要再主动发送请求由表格代理增删改查的相关调用逻辑只需要配好对应的接口即可自动渲染<br>
响应结果默认必须是数组非数组情况下可以通过 <grid-api-link prop="props"/> 修改
</p>
<vxe-grid
border
resizable
height="530"
:loading="loading"
:seq-config="{startIndex: (tablePage.currentPage - 1) * tablePage.pageSize}"
:pager-config="tablePage"
:columns="tableColumn"
:data="tableData"
@page-change="handlePageChange"></vxe-grid>
<p class="demo-code">{{ $t('app.body.button.showCode') }}</p>
<pre>
<code class="xml">{{ demoCodes[0] }}</code>
<code class="javascript">{{ demoCodes[1] }}</code>
</pre>
</div>
</template>
<script>
import XEAjax from 'xe-ajax'
import hljs from 'highlight.js'
export default {
data () {
return {
loading: false,
tablePage: {
total: 0,
currentPage: 1,
pageSize: 10,
align: 'left',
pageSizes: [10, 20, 50, 100, 200, 500],
layouts: ['Sizes', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total'],
perfect: true
},
tableColumn: [
{ type: 'seq', width: 60 },
{ type: 'checkbox', width: 50 },
{ field: 'name', title: 'Name' },
{ field: 'nickname', title: 'Nickname' },
{ field: 'role', title: 'Role' },
{ field: 'describe', title: 'Describe', showOverflow: true }
],
tableData: [],
demoCodes: [
`
<vxe-grid
border
resizable
height="530"
:loading="loading"
:seq-config="{startIndex: (tablePage.currentPage - 1) * tablePage.pageSize}"
:pager-config="tablePage"
:columns="tableColumn"
:data="tableData"
@page-change="handlePageChange"></vxe-grid>
`,
`
export default {
data () {
return {
loading: false,
tablePage: {
total: 0,
currentPage: 1,
pageSize: 10,
align: 'left',
pageSizes: [10, 20, 50, 100, 200, 500],
layouts: ['Sizes', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total'],
perfect: true
},
tableColumn: [
{ type: 'seq', width: 60 },
{ type: 'checkbox', width: 50 },
{ field: 'name', title: 'Name' },
{ field: 'nickname', title: 'Nickname' },
{ field: 'role', title: 'Role' },
{ field: 'describe', title: 'Describe', showOverflow: true }
],
tableData: []
}
},
created () {
this.findList()
},
methods: {
findList () {
// 模拟后台接口
this.loading = true
XEAjax.get(\`/api/user/page/list/\${this.tablePage.pageSize}/\${this.tablePage.currentPage}\`).then(({ page, result }) => {
this.tableData = result
this.tablePage.total = page.total
this.loading = false
}).catch(e => {
this.loading = false
})
},
searchEvent () {
this.tablePage.currentPage = 1
this.findList()
},
handlePageChange ({ currentPage, pageSize }) {
this.tablePage.currentPage = currentPage
this.tablePage.pageSize = pageSize
this.findList()
}
}
}
`
]
}
},
created () {
this.findList()
},
mounted () {
Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
hljs.highlightBlock(block)
})
},
methods: {
findList () {
// 模拟后台接口
this.loading = true
XEAjax.get(`/api/user/page/list/${this.tablePage.pageSize}/${this.tablePage.currentPage}`).then(({ page, result }) => {
this.tableData = result
this.tablePage.total = page.total
this.loading = false
}).catch(e => {
this.loading = false
})
},
searchEvent () {
this.tablePage.currentPage = 1
this.findList()
},
handlePageChange ({ currentPage, pageSize }) {
this.tablePage.currentPage = currentPage
this.tablePage.pageSize = pageSize
this.findList()
}
}
}
</script>