Files
vxe-table/examples/views/table/plugin/ExportPDF.vue
xuliangzhan 7a3a94e0aa 更新文档
2019-11-15 17:35:27 +08:00

131 lines
4.3 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">
具体兼容请查看 <a class="link" href="https://www.npmjs.com/package/vxe-table-plugin-export-pdf" target="_blank">vxe-table-plugin-export-pdf</a> 插件的 API<br>
<span class="red">目前无法支持中文字体会乱码可自行引入字体库解决</span>
</p>
<vxe-toolbar setting :export="tableExport"></vxe-toolbar>
<vxe-table
border
height="400"
:loading="loading"
:data="tableData">
<vxe-table-column type="checkbox" width="60"></vxe-table-column>
<vxe-table-column type="index" width="60"></vxe-table-column>
<vxe-table-column field="name" title="Name"></vxe-table-column>
<vxe-table-column field="role" title="Role"></vxe-table-column>
<vxe-table-column field="sex" title="Sex"></vxe-table-column>
<vxe-table-column field="age" title="Age"></vxe-table-column>
<vxe-table-column field="rate" title="Rate"></vxe-table-column>
</vxe-table>
<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 hljs from 'highlight.js'
export default {
data () {
return {
loading: false,
tableData: [],
tableExport: {
// 默认选中类型
type: 'pdf',
// 自定义类型
types: ['pdf', 'csv', 'html', 'xml', 'txt']
},
demoCodes: [
`
<vxe-toolbar setting :export="tableExport"></vxe-toolbar>
<vxe-table
border
height="400"
:loading="loading"
:data="tableData">
<vxe-table-column type="checkbox" width="60"></vxe-table-column>
<vxe-table-column type="index" width="60"></vxe-table-column>
<vxe-table-column field="name" title="app.body.label.name"></vxe-table-column>
<vxe-table-column field="role" title="Role"></vxe-table-column>
<vxe-table-column field="sex" title="app.body.label.sex"></vxe-table-column>
<vxe-table-column field="age" title="app.body.label.age"></vxe-table-column>
<vxe-table-column field="rate" title="Rate"></vxe-table-column>
</vxe-table>
`,
`
export default {
data () {
return {
loading: false,
tableData: [],
tableExport: {
// 默认选中类型
type: 'pdf',
// 自定义类型
types: ['pdf', 'csv']
}
}
},
created () {
this.findList()
},
methods: {
findList () {
this.loading = true
setTimeout(() => {
this.tableData = [
{ name: 'name1', role: 'role1', sex: '0', age: 22, rate: 5 },
{ name: 'name2', role: 'role2', sex: '1', age: 32, rate: 1 },
{ name: 'name3', role: 'role3', sex: '1', age: 26, rate: 1 },
{ name: 'name4', role: 'role4', sex: '0', age: 28, rate: 4 },
{ name: 'name5', role: 'role5', sex: '1', age: 24, rate: 3 }
]
this.loading = false
}, 100)
}
}
}
`
]
}
},
created () {
this.findList()
},
mounted () {
Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
hljs.highlightBlock(block)
})
},
methods: {
findList () {
this.loading = true
setTimeout(() => {
this.tableData = [
{ name: 'name1', role: 'role1', sex: '0', age: 22, rate: 5 },
{ name: 'name2', role: 'role2', sex: '1', age: 32, rate: 1 },
{ name: 'name3', role: 'role3', sex: '1', age: 26, rate: 1 },
{ name: 'name4', role: 'role4', sex: '0', age: 28, rate: 4 },
{ name: 'name5', role: 'role5', sex: '1', age: 24, rate: 3 },
{ name: 'name6', role: 'role6', sex: '1', age: 19, rate: 3 },
{ name: 'name7', role: 'role7', sex: '1', age: 18, rate: 3 },
{ name: 'name8', role: 'role8', sex: '2', age: 29, rate: 3 },
{ name: 'name9', role: 'role9', sex: '1', age: 21, rate: 3 }
]
this.loading = false
}, 100)
}
}
}
</script>