xref: /openbmc/webui-vue/src/components/Global/TableToolbarExport.vue (revision 883a0d597962dfd30d6c48319b8b33e2d0f98606)
1<template>
2  <b-button
3    class="d-flex align-items-center"
4    variant="primary"
5    :download="download"
6    :href="href"
7  >
8    {{ $t('global.action.export') }}
9  </b-button>
10</template>
11
12<script>
13import { useI18n } from 'vue-i18n';
14export default {
15  props: {
16    data: {
17      type: Array,
18      default: () => [],
19    },
20    fileName: {
21      type: String,
22      default: 'data',
23    },
24  },
25  data() {
26    return {
27      $t: useI18n().t,
28    };
29  },
30  computed: {
31    dataForExport() {
32      return JSON.stringify(this.data);
33    },
34    download() {
35      return `${this.fileName}.json`;
36    },
37    href() {
38      return `data:text/json;charset=utf-8,${this.dataForExport}`;
39    },
40  },
41};
42</script>
43