使用 iview 导出 csv 表格时,里面数据为空,这是咋回事.
<template>
<div>
<Input v-model="keyword" placeholder="搜索关键字" class="input" @keyup.enter.native="handleFilter" />
<Button @click="handleFilter" class="button" type="primary" icon="ios-search">搜索</Button>
<Button @click="exportData" class="download-button" type="primary" icon="ios-download-outline">导出数据</Button>
<Table :show-header="false" :data="tableData" :columns="columns" ref="tables">
<template slot-scope="{ row }" slot="url">
<div v-if="row.url" class="div">
<a target="_blank" :href="row.url" > {{ row.url }}</a>
<Button @click="doCopy(row.url)" type="info" class="fuzhi" size="small">复制</Button>
</div>
</template>
</Table>
<Page
class="page"
:current="this.page.pageNum"
:page-size="this.page.pageSize"
:total= "this.page.count"
:page-size-opts="[10,20,30,50,100]"
show-sizer
show-elevator
show-total
@on-change="handlePage"
@on-page-size-change="handlePageSize">
</Page>
</div>
</template>
<script>
import RSA from '@/libs/crypto'
import { search } from '@/api/search'
export default {
inject: ['reload'],
name: 'SearchIndex',
data () {
return {
token: getToken(),
keyword: '',
page: {
pageNum: 1,
pageSize: 10,
count: 0
},
columns: [
{
slot: 'url',
align: 'center'
},
{
slot: 'banner'
}
],
tableData: []
}
},
methods: {
getTableData () {
let data = {
'pagenum': this.page.pageNum,
'pagesize': this.page.pageSize,
}
data = JSON.stringify(data)
let params = { 'data': RSA.Encrypt(data) }
search(params).then(response => {
this.tableData = response.data
this.page.count = response.total
})
},
exportData () {
this.$refs.tables.exportCsv({
filename: `${(new Date()).valueOf()}.csv`
})
}
}
}
</script>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.