html 包含h5,下载文件,预览文件
安卓下载
exportPDF(url) { // url 未pdf,word文件可以打开的链接
const a = document.createElement("a");
a.href = url;
a.target="_blank";
a.download = "download";
a.click();
},
ios下载(uni-app demo)
<template>
<view style='margin-top:200px;'>
<u-button type="success" @click='exportPDF' style='width:80%;'>点击下载PDF</u-button>
</view>
</template>
<script>
// u-view 1 参考:https://v1.uviewui.com/components/upload.html
import util from '@/util/utils.js'
export default {
data() {
return {
pdfUrl:''
}
},
onLoad(op) {
console.log(op.url);
this.pdfUrl=op.url;
},
methods: {
exportPDF() {
const downloadElement = document.createElement("a");
downloadElement.href = this.pdfUrl;
downloadElement.download = "download";
// a.click();
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
}
}
}
</script>
<style>
</style>
- uni-app的h5 h5 web 应该均可以实现,url为接口动态获取的
相信坚持的力量,日复一日的习惯.