当前位置:网站首页>A label_ File download (download attribute)
A label_ File download (download attribute)
2022-07-28 13:56:00 【Good [email protected]】
Requirements describe
- demand : When the button is clicked , You can download the template
- The download address is a remote link —>https://file2.clipworks.com/4c217acc09226795a7ebb8461ddf548f/20220726/469c1056-749d-4c47-819e-35f91c70e163
Implementation process
notes : If you don't understand something, you can first look at the knowledge points below ~
Realization
<div>
<a class="el-button el-button--primary el-button--mini" href='https://file2.clipworks.com/4c217acc09226795a7ebb8461ddf548f/20220726/469c1056-749d-4c47-819e-35f91c70e163' download=" Video tutorial template "> Template download </a>
</div>
- a The label style is elementUI The style of the button in
problem
if href The attribute value is server link instead of local link , When clicked, it will not download but jump to the current url!
reason
Because download Attributes have homologous policies , If it is not the same source, it will not download but jump !
solve
since a There is a homology strategy for label downloading , We will create a local based on the remote link url;
<template>
<div style="margin-top:20px">
<a class="el-button el-button--primary el-button--mini" :href='url' download=" Video tutorial template " id='downloadBtn' target='_blank'> Template download </a>
</div>
</template>
<script>
export default {
data(){
return{
url:undefined
}
},
created(){
this.getLocalUrl()
},
methods:{
getLocalUrl(){
// To create local url
const url = 'https://file2.clipworks.com/4c217acc09226795a7ebb8461ddf548f/20220726/469c1056-749d-4c47-819e-35f91c70e163'
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.responseType = "blob"
xhr.onload = ()=>{
console.log('res', xhr.response)
this.url = URL.createObjectURL(xhr.response)
}
xhr.onerror = e =>{
console.log('err', e)
}
xhr.send()
}
}
}
</script>
Knowledge point
Knowledge point 1-a Labeled download attribute
- download The attribute is h5 Newly added a Tag attributes !
- download The function of attribute is : Instruct the browser to download URL Instead of navigating to URL; download Property value It will be used as the pre filled file name during the download and save process ;
- Be careful :
- if url For remote links , There is a homology policy for this attribute —> From different sources url Instead of downloading, you can jump directly ;
- Compatibility is not good (ie I won't support it )
Knowledge point 2- Native http request
Knowledge point 3- To create local url
版权声明
本文为[Good [email protected]@@]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207281250142827.html
边栏推荐
- 不用Swagger,那我用啥?
- UVA11175有向图D和E From D to E and Back题解
- 数据库系统原理与应用教程(059)—— MySQL 练习题:操作题 1-10(三)
- Deploy application delivery services in kubernetes (Part 1)
- word打字时后面的字会消失是什么原因?如何解决?
- Poj3275 ranking the cows
- C language: random generated number + merge sort
- Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question
- Understanding of stack and practical application scenarios
- UVA1599理想路径题解
猜你喜欢

Deploy application delivery services in kubernetes (Part 1)

国产API管理工具Eolink太好用了,打造高效的研发利器

SLAM论文合集

安全保障基于软件全生命周期-PSP应用

Three men "running away" from high positions in the mobile phone factory

111. The sap ui5 fileuploader control realizes local file upload and encounters a cross domain access error when receiving the response from the server

不用Swagger,那我用啥?

After finishing, help autumn move, I wish you call it an offer harvester

Better and more modern terminal tools than xshell!

30天刷题计划(四)
随机推荐
国产API管理工具Eolink太好用了,打造高效的研发利器
Socket class understanding and learning about TCP character stream programming
The domestic API management tool eolink is very easy to use, creating an efficient research and development tool
Lyscript get previous and next instructions
Uva11175 digraph D and E from D to e and back
Can second uncle cure young people's spiritual internal friction?
R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram and set draw_ The quantiles parameter adds a specified quantile horizontal line (for example, 50%
【架构】评分较高的三本微服务书籍的阅读笔记
What is the reason why the words behind word disappear when typing? How to solve it?
对“Image Denoising Using an Improved Generative Adversarial Network with Wasserstein Distance“的理解
Li Kou sword finger offer 51. reverse order pairs in the array
Use non recursive method to realize layer traversal, preorder traversal, middle order traversal and post order traversal in binary tree
数据库系统原理与应用教程(059)—— MySQL 练习题:操作题 1-10(三)
The strongest distributed locking tool: redisson
How to play a data mining game entry Edition
R语言使用dpois函数生成泊松分布密度数据、使用plot函数可视化泊松分布密度数据(Poisson distribution)
UVA1599理想路径题解
[C language] the difference between structure pointer and structure variable as formal parameters
Vite configuring path aliases in the project
es6你用过哪些惊艳的写法