vue-json-csv icon indicating copy to clipboard operation
vue-json-csv copied to clipboard

How change filename after click download

Open yuta86 opened this issue 4 years ago • 1 comments

Hello. Thank you for your library. How I can generate filename after click button?

<download-csv
  :data=fraudErrorsForCSV
  :name="CSVFileName"
  ref="export"
  hidden
>
</download-csv>

<v-btn
  color="green"
  rounded
  @click="createFileName">
  Errors(csv)
</v-btn>

createFileName () {
      var currentdate = new Date()
      this.CSVFileName = `log_${currentdate.getDate()}-${currentdate.getMonth()}-${currentdate.getFullYear()} ${currentdate.getHours()}-${currentdate.getMinutes()}-${currentdate.getSeconds()}.csv`
      this.$refs.export.generate()
    },

data () { return { CSVFileName: null, .... }

yuta86 avatar Sep 16 '21 14:09 yuta86

Hello

Why do you want a button to generate a fileName ? The lib does it for you.

Couldn't you just use a getter to do something like

get CSVFileName() {
    var currentdate = new Date();
    return `log_${currentdate.getDate()}-${currentdate.getMonth()}-${currentdate.getFullYear()} ${currentdate.getHours()}-${currentdate.getMinutes()}-${currentdate.getSeconds()}.csv`;
}

You can also wrap your button with the lib component like that, it will only render the button

<download-csv
  :data=fraudErrorsForCSV
  :name="CSVFileName"
  ref="export"
>
  <v-btn color="green"  rounded>
    Errors(csv)
  </v-btn>
</download-csv>

ioaNikas avatar Nov 18 '21 08:11 ioaNikas