【问题标题】:ReactJS- downloading a pdf file "Failed - no file"ReactJS-下载pdf文件“失败-无文件”
【发布时间】:2019-05-28 19:35:30
【问题描述】:

我编写了一个 React 组件来使用文件的 achor 标签下载 pdf 文件。我收到一个错误Failed- No file

import React from 'react'

const Links = ()=>
        <div className='github-link'>
             <a href="https://github.com/" rel='noopener noreferrer'  alt="github link"
     target='_blank'><strong>View my GitHub here!</strong></a>
     <a href="../resume/resume.pdf" download><strong>Download my Resume!</strong></a>
        </div>



export default Links

我的简历 pdf 在我的 src 目录中的一个名为 resume 的目录中。我要下载的文件叫做 resume.pdf

感谢您的帮助!

【问题讨论】:

  • 我也面临同样的问题。你能找到解决办法吗?

标签: javascript html reactjs


【解决方案1】:

简单的解决方法是将pdf文件放入您的public文件夹并设置href="resume.pdf"

您也可以在public 中创建一个名为resume 的文件夹,并将pdf 文件放入您的resume 文件夹中。

<a href="/resume/resume.pdf" download><strong>Download my Resume!</strong></a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    相关资源
    最近更新 更多