当前位置:网站首页>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
边栏推荐
- What is the reason why the words behind word disappear when typing? How to solve it?
- es6你用过哪些惊艳的写法
- DDoS protection with iptables
- No swagger, what do I use?
- leetcode(442)数组中重复的数据
- 使用 IPtables 进行 DDoS 保护
- 30天刷题计划(四)
- R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(使用参数xlim和ylim将标签添加到可视化图像的特定区域、指定标签线段并添加箭头)
- UVA11175有向图D和E From D to E and Back题解
- R语言ggplot2可视化:可视化散点图并为散点图中的数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点标签互相重叠(自定义指定字体类型font family)
猜你喜欢

No swagger, what do I use?

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

strcmp、strstr、memcpy、memmove的实现

What is the reason why the words behind word disappear when typing? How to solve it?

Socket class understanding and learning about TCP character stream programming

酷炫操作预热!代码实现小星球特效

产品经理:岗位职责表

Denial of service DDoS Attacks

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

最强分布式锁工具:Redisson
随机推荐
Vite configuring path aliases in the project
【安全】 阅读 RFC6749 及理解 Oauth2.0 下的授权码模式
数据库系统原理与应用教程(060)—— MySQL 练习题:操作题 11-20(四)
Continuous (integration -- & gt; delivery -- & gt; deployment)
30 day question brushing plan (IV)
安全保障基于软件全生命周期-Istio的认证机制
SLAM论文合集
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)
Rolling update strategy of deployment.
[Architecture] reading notes of three micro service books with high scores
vite在项目中配置路径别名
To build agile teams, these methods are indispensable
R language Visual scatter diagram, geom using ggrep package_ text_ The repl function avoids overlapping labels between data points (add labels to specific areas of the visual image using the parameter
The strongest distributed locking tool: redisson
leetcode-深度优先与广度优先遍历
SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误的试读版
Humiliation, resistance, reversal, 30 years, China should win Microsoft once
要想组建敏捷团队,这些方法不可少
What if the server cannot be connected (the original server cannot find the target resource)
Customized template in wechat applet