I have retrieved some data from websocket server, is is possible to generate a file download event so that the user can save arbitrary data to disk?
Normally people would access a new URL to export data, I'm trying to avoid that.
I have retrieved some data from websocket server, is is possible to generate a file download event so that the user can save arbitrary data to disk?
Normally people would access a new URL to export data, I'm trying to avoid that.
To create a file in memory using vue.js you can use the example below:
<div id="app"> <a v-on:click="download()" :href="myUrl" :download="myfilename">DOWNLOAD</a> </div> <script> var app = new Vue({ el: '#app', data: { myUrl: '#', myFilename: '' }, methods: { download: function() { const jsonData = encodeURIComponent('{"is_valid": true}') this.myUrl = `data:text/plain;charset=utf-8,${jsonData}` this.myFilename = 'example.json' } } }) </script>