1

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?

1 Answer 1

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.