【问题标题】:Nuxt 3 navigateTo method to open in a new tabNuxt 3 navigateTo 方法在新选项卡中打开
【发布时间】:2022-10-24 20:09:35
【问题描述】:

我想使用 navigateTo 方法将用户重定向到新选项卡中的外部链接。例如,我找不到类似于在 html 标记 <a href="https://google.com" target="_blank"> 中使用 target="_blank" 的选项

有没有办法在navigateTo 方法中添加这样的参数?

<script lang = "ts" setup>
 function onEventTriggered() {
    return navigateTo('https://google.com', {
      external: true,
    })
  } 
</script>

【问题讨论】:

    标签: vue.js vuejs3 nuxtjs3


    【解决方案1】:

    我不确定您是否可以使用名为navigateTo 的方法在另一个选项卡中“打开”某些内容,因为它的命名会非常不直观和奇怪。

    你可以尝试this approach tho,模拟完全相同的东西,甚至不需要将它添加到 DOM

    <script setup>
    function openExternal(endpoint) {
      const link = document.createElement('a')
      link.href = endpoint
      link.target = '_blank'
      link.click()
    }
    </script>
    
    <template>
      <button @click="openNewTab('https://google.com')">
        Open in new tab
      </button>
    </template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-25
      • 2017-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-09
      • 2016-09-12
      相关资源
      最近更新 更多