- <template>
- <el-dialog v-model="downExcel.downExcelDialog" title="下载成功" width="300">
- <a
- style="color: #409eff"
- :href="downExcel.href"
- :download="downExcel.fileName"
- target="_blank"
- ref="downloadLink"
- >
- {{ downExcel.fileName }}
- </a>
- </el-dialog>
- </template>
- <script lang="ts" setup>
- import { reactive, ref } from "vue";
- const downExcel = reactive({
- downExcelDialog: false,
- href: "",
- fileName: "",
- });
- const downloadLink = ref();
- defineExpose({
- openDialog,
- });
- function openDialog(fileData, fileName) {
- const blob = new Blob([fileData], {
- type: "application/octet-stream",
- });
- var href = window.URL.createObjectURL(blob); // 创建下载的链接
- downloadLink.value = href;
- downExcel.href = href;
- downExcel.fileName = fileName;
- downExcel.downExcelDialog = true;
- }
- </script>
复制代码
a标签点击不会打开新的页面下载文件,已经设置了 target="_blank"
|