在 Vue3 中点击按钮跳转到外部网站新的标签页中打开外部网站
在 Vue3 中,你可以使用window.open()方法来在新的标签页中打开外部网站。你可以将该方法绑定到按钮的点击事件上。
首先,在你的组件模板中添加一个按钮元素,例如:
<template>
<button @click="openExternalWebsite">打开外部网站</button>
</template>
然后,在你的组件的methods选项中定义一个openExternalWebsite方法,使用window.open()方法来打开外部网站,例如:
<script>
export default {
methods: {
openExternalWebsite() {
window.open("https://www.example.com", "_blank");
}
}
}
</script>
在上面的示例中,window.open()方法接受两个参数。第一个参数是外部网站的 URL,第二个参数是目标窗口的名称。在这里,我们将目标窗口的名称设置为"_blank",这将在新的标签页中打开外部网站。
这样,当你点击按钮时,Vue3将调用openExternalWebsite方法,并在新的标签页中打开外部网站。
原文地址: https://www.cveoy.top/t/topic/i5vp 著作权归作者所有。请勿转载和采集!