3

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.

2

1 Answer 1

1

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> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.