![]() |
严肃的茶叶 · Java集成OpenCV总结 - ...· 昨天 · |
![]() |
文武双全的热带鱼 · 关于输入法栏删掉美式键盘后反复出现美式键盘的 ...· 5 小时前 · |
![]() |
紧张的手电筒 · ClickHouse 与es比较 - 简书· 1 年前 · |
![]() |
任性的跑步鞋 · 解决python问题 Traceback ( ...· 1 年前 · |
![]() |
俊秀的石榴 · 圣华女学院雷火剑预告 - 抖音· 1 年前 · |
![]() |
酒量小的杯子 · 西安软件新城未来10年后房价能到5万么?相当 ...· 1 年前 · |
这可能很简单,但我已经查看了文档,但找不到任何关于它的信息。我想让我的'github‘链接重定向到github.com。然而,它只是将' https://github.com ‘附加到我的url中,而不是跟随链接。下面是一个代码片段:
<BreadcrumbItem to='https://github.com'>
<Icon type="social-github"></Icon>
</BreadcrumbItem>
(这是对自定义CSS使用iView,但'to‘的工作方式与路由器链接相同)。
最终发生的是这样的:
我阅读了Daniel的链接,并找到了一个解决方法:
{
path: '/github',
beforeEnter() {location.href = 'http://github.com'}
}
<a :href="'//' + websiteUrl" target="_blank">
{{ url }}
</a>
只需将链接块放在breadcrumb项中,如下所示:
<BreadcrumbItem>
<a href="https://github.com">
<Icon type="social-github"/>
</BreadcrumbItem>
const github = { template: '<div>github</div>'}
const routes = [
path: '/github',
beforeEnter() {location.href = 'http://github.com'},
component: github
const router = new VueRouter({
routes
const app = new Vue({
router
}).$mount('#app')
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<div id="app">
<li><router-link to="/github">github.com</router-link></li>
<router-view></router-view>
</body>
如果需要,一种更动态的方法是仅覆盖某些方法,以检测何时应使用
route.meta.external
以外部方式处理路由
// Override matcher to fix external links.
const match = router.matcher.match
router.matcher.match = (...args) => {
let route = match.apply(router, args)
if (!route.meta.external) {
return route
return Object.freeze({...route, fullPath: route.path})
// Override resolver to fix external links.
const resolve = router.resolve
router.resolve = (...args) => {
const resolved = resolve.apply(router, args)
if (resolved.route.meta.external) {
resolved.href = resolved.route.fullPath
return resolved
// Handle external routes.
router.beforeEach((to, from, next) => {
if (to.meta.external) {
if (to.meta.newWindow) {
window.open(to.fullPath)
else {
window.location.replace(to.fullPath)
return next(false)
next()
})
我这样做的方式是使用一个方法
<button @click="redirect('https://www.google.com')>Click me</button>
methods:
redirect: function (link, target = '_blank') {
window.open(link, target);
}
这只是一个例子,我通常在根组件上创建方法,并且可以使用$parent或bus访问它,具体取决于项目类型。
只需使用"//“而不是http或https。这对我在路由器文件中是有效的。
我将在我的路由器配置文件中创建一个新路由,并在新选项卡中打开指向我的外部链接的路由。
{
name: "Github",
beforeEnter() {
window.open('https://www.github.com/', '_blank')
component: MyComponent,
},
然后,在我的模板中,我将创建一个简单的按钮,该按钮调用一个带有外部链接的新路由的函数。
<button @click="onUserClick('Github')">Github</button>
setup () {