evrenior
evrenior

Reputation: 33

How download json file on button click in vue js app

I should download json file on button click. When I click, I make a request to api and the following response:

{
  data: {…},
  status: 200,
  statusText: "",
  headers: {…},
  config: {…},
  …
}

but how can I download json file on button clicking with this response from backend?

Upvotes: 1

Views: 4376

Answers (1)

s4k1b
s4k1b

Reputation: 3095

You can use a library like downloadjs

import downloadjs in the the component where your button is. attach a onClick event listenerr to your button and perform the following operation using downloadjs

download(JSON.stringify(apiResponse), "apidata.json", "text/plain");

Upvotes: 2

Related Questions