Vue
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<div id="app">
<div id="down" @click="downloadIt()">
download
</div>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
#down {
cursor: pointer;
}
Vue
new Vue({
el: "#app",
data: {
},
methods: {
downloadIt () {
axios.get('https://enable-cors.org/img/corsinaction-cover-w140.jpg', {responseType: 'blob'})
.then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'image.png');
document.body.appendChild(link);
link.click();
})
}
}
})