summaryrefslogtreecommitdiff
path: root/src/components/Global/TableToolbarExport.vue
blob: ed1d980fa2753003d7982946b31361dcd4cff5c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<template>
  <b-link
    class="btn btn-primary d-block align-self-center"
    :download="download"
    :href="href"
  >
    {{ $t('global.action.export') }}
  </b-link>
</template>

<script>
export default {
  props: {
    data: {
      type: Array,
      default: () => []
    },
    fileName: {
      type: String,
      default: 'data'
    }
  },
  computed: {
    dataForExport() {
      return JSON.stringify(this.data);
    },
    download() {
      return `${this.fileName}.json`;
    },
    href() {
      return `data:text/json;charset=utf-8,${this.dataForExport}`;
    }
  }
};
</script>