沉稳的手链 · ps cs6 英文语言包 - CSDN文库· 1 月前 · |
温柔的人字拖 · 完全卸载photoshop教程 - CSDN文库· 1 月前 · |
朝气蓬勃的木瓜 · stata中的数据类型 - CSDN文库· 4 周前 · |
开心的山羊 · 哥布林洞窟百度云 - 百度· 3 周前 · |
踢足球的围巾 · oreo大师作品合集百度网盘 - 抖音· 2 周前 · |
儒雅的羊肉串 · c# - How can I tell ...· 1 年前 · |
霸气的佛珠 · iOS-单元测试/性能测试_测试ssy-CS ...· 1 年前 · |
小眼睛的热带鱼 · ICommand 介面 ...· 1 年前 · |
聪明伶俐的铁板烧 · Tableau 文件类型和文件夹 - ...· 1 年前 · |
笑点低的小摩托 · SQL工具性能实测:居然比Navicat还快 ...· 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 () {
沉稳的手链 · ps cs6 英文语言包 - CSDN文库 1 月前 |
温柔的人字拖 · 完全卸载photoshop教程 - CSDN文库 1 月前 |
朝气蓬勃的木瓜 · stata中的数据类型 - CSDN文库 4 周前 |
开心的山羊 · 哥布林洞窟百度云 - 百度 3 周前 |
踢足球的围巾 · oreo大师作品合集百度网盘 - 抖音 2 周前 |
儒雅的羊肉串 · c# - How can I tell when .Net System.Diagnostics.Process ran successfully or failed? - Stack Overflo 1 年前 |
霸气的佛珠 · iOS-单元测试/性能测试_测试ssy-CSDN博客 1 年前 |