this.$http
.get(
"your-url",
{
responseType: "blob" ,//重要
}
)
.then(response => {
if (response.message) {
this.$message.error(response.message)
return
}
let blob = new Blob([response.data], { type: "application/zip" })
let link = document.createElement("a")
let url = window.URL.createObjectURL(blob)
link.href = url
link.download = this.projectName
link.click()
URL.revokeObjectURL(url)//释放内存
})
.catch((e) => {
this.$message.error(this.$store.getters.$lang.messages.errorLoad+":"+e)
})
}
<template>
<div v-viewer="{'toolbar': true,'navbar': false, 'title': false}"
class="images clearfix"
@ready="readys"
@shown="shown">
<slot></slot>
</div>
</template>
<script>
export default {
name: "Preview",
data() {
return {}
},
mounted() {
this.$nextTick(() => {
})
},
methods: {
readys() {
var toolbar = this.jquery(this.$el.viewer.viewer).find(".viewer-toolbar")
var downLoadEle = this.jquery('<li role="button" class="downLoadImg" data-viewer-action="downLoadImg" style="display: flexalign-items: centerjustify-content: center"><i style="color: whitefont-size: 14px" class="iconfont icontupiandanchuang-xiazaitubiao1"></i></li>')
if (toolbar.find("downLoadImg").length != 0) {
return
}
toolbar.find("ul").append(downLoadEle)
},
shown() {
var self = this
this.jquery(".downLoadImg").off().on("click", function() {
location.href = self.jquery(".viewer-canvas img").attr("src")
})
}
}
}
</script>
<style scoped>
</style>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)