vue-json-csv
vue-json-csv copied to clipboard
How change filename after click download
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, .... }
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>