简体   繁体   English

Vuejs 在新标签页中打开 PDF 文件

[英]Vuejs open a PDF file in a new tab

My actual code do the PDF download, its working fine.我的实际代码进行 PDF 下载,工作正常。 But instead of download i would like to open the PDF file in a new tab.但我想在新选项卡中打开 PDF 文件,而不是下载。 Can anyone help?任何人都可以帮忙吗?

''' '''

<div class="table__buttons display-if">
    <template v-for="action in meta.actions">
      <a
        v-if="action === 'buttonDownload'"
        :key="action"
        :href="actions(action).to"
        :target="actions(action).target"
        :class="actions(action).class">
        <btn-table
          :tooltip="actions(action).tooltip"
          :icon-name="actions(action).iconName"
          type="button--table"
        />
      </a>

...

methods: {
    actions (action) {
      const { item, routes } = this.meta
      const actions = {
        // Actions params
        buttonDownload: {
          to: `${item['link']}`,
          target: '_blank',
          iconName: 'icon-download',
          tooltip: routes.buttonDownloadTooltip
        },

尝试在内联中添加 target='_blank'

To view a PDF without downloading, try using window.open('url/for/pdf', '_blank') .要在不下载的情况下查看 PDF,请尝试使用window.open('url/for/pdf', '_blank') This can be achieved by using a Vue click event handler rather than the default <a> tag behavior, like so:这可以通过使用 Vue 单击事件处理程序而不是默认的<a>标签行为来实现,如下所示:

<a
    v-if="action === 'buttonDownload'"
    :key="action"
    :class="actions(action).class"
    @click.prevent="window.open(actions(action).to, '_blank')"
>
    ...
</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM