<template>
    <div class="result-table">
      <b-table striped hover bordered :items="items"></b-table>
      <button type="button" class="kalacloudExportExcel-button" v-on:click="download">导出至 Excel</button>
    </div>
</template>

<style scoped>
.result-table {
  width: 70%;
  text-align: center;
}
.kalacloudExportExcel-button {
  background-color: DodgerBlue;
  border: none;
  color: white;
  padding: 12px 30px;
  margin: 12px 0;
  cursor: pointer;
  font-size: 20px;
}

.kalacloudExportExcel-button:hover {
  background-color: RoyalBlue;
}
</style>

<script>
import { BTable } from 'bootstrap-vue'
import XLSX from 'xlsx'
export default {
  name: 'kalacloudExportExcel',
  components: {
    BTable
  },
  data () {
    return {
      items: [
        { '姓名': '谢国庆', '年龄': 29, '电话': '13697653219' },
        { '姓名': '吕小果', '年龄': 25, '电话': '13235789213' },
        { '姓名': '宋阿美', '年龄': 27, '电话': '13756776977' },
        { '姓名': '蒋铁柱', '年龄': 33, '电话': '15003373377' }
      ]
    }
  },
  methods: {
    download: function () {
      const data = XLSX.utils.json_to_sheet(this.items)
      const wb = XLSX.utils.book_new()
      XLSX.utils.book_append_sheet(wb, data, 'kalacloud-data')
      XLSX.writeFile(wb, 'kalacloudExportExcel.xlsx')
    }
  }
}
</script>
