zoukankan      html  css  js  c++  java
  • vue中前端实现下载excel文件,.csv文件, .sql文件;打开pdf文件

     客户只要求下载csv文件:

    DOM部分:

    <el-table-column prop="path" align="center" label="Action">
                    <template slot-scope="scope">
                      <el-link
                        v-if="scope.row.status == 2"
                        class="export"
                        @click="openPdf(scope.row)"
                        :underline="false"
                        >{{ $t('events.download') }}</el-link
                      >
                      <el-link v-else :underline="false" style="cursor: text"
                        >--</el-link
                      >
                    </template>
    </el-table-column>

    JS部分:

    使用a标签可以在当前窗口打开,不会出现闪屏

    openPdf(row) {
        // status === 2说明后端返回的地址是成功的
    if (row.status === 2) { const a = document.createElement('a') a.href = row.path // 这里的请求方式为get,如果需要认证,接口上需要带上token a.click() return false } else { return false } },

     打开PDF:后端返回pdf的链接:

    openPdf(row) {
          if (row.status === 2) {
            window.open(`${row.path}`)
          } else {
            return false
          }
        }

  • 相关阅读:
    linux下使用OpenCV的一些问题
    Google Colab调用cv2.imshow奔溃
    [LeetCode] Word Search
    信号
    信号
    [Leetcode] Subsets
    [LeetCode] Combinations
    [LeetCode] Minimum Window Substring
    [LeetCode] Set Matrix Zeroes
    sigaction 函数
  • 原文地址:https://www.cnblogs.com/hahahakc/p/13995265.html
Copyright © 2011-2022 走看看