screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.22/dist/vue.global.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"> <h3>Vue Js Download Pdf from API | Using Axios </h3> <button @click="downloadFile">Download File</button> </div> <script type="module"> const app = Vue.createApp({ methods: { downloadFile() { axios({ url: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', method: 'GET', responseType: 'blob', }).then(response => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', 'dummy.pdf'); document.body.appendChild(link); link.click(); }); }, }, }); app.mount('#app'); </script> </body> </html>