VUE3(二十一)vue-router 在新窗口打开页面的功能

新窗口打开标签页这个功能在html中还是很简单的。添加Target=”__blank”就好。

但是在vue中怎么实现呢?

其实很简单:

VUE2:

const { href } = this.$router.resolve({
        name: `print_schedule`,
        params: {
          id: id
        }
      });
      window.open(href, "_blank");

VUE3:

const router = useRouter();
const { href } = router.resolve({
                path: '/pc/articleDetail',
                query: {
                    article_id: utils.encryptCode({ 'article_id': article_id })
                }
            });
            window.open(href, "_blank");

上边大概展示了其在VUE2和VUE3中使用的方法。

有好的建议,请在下方输入你的评论。

欢迎访问个人博客
https://guanchao.site

你可能感兴趣的:(VUE3(二十一)vue-router 在新窗口打开页面的功能)