refactor[ExternalLink]: tweak externalLink judge

This commit is contained in:
Pan 2018-08-28 18:24:06 +08:00
parent 61394e573e
commit d54bdc8fff
1 changed files with 10 additions and 9 deletions

View File

@ -2,17 +2,11 @@
<div v-if="!item.hidden&&item.children" class="menu-wrapper">
<template v-if="hasOneShowingChild(item.children) && !onlyOneChild.children&&!item.alwaysShow">
<a v-if="isExternalLink(onlyOneChild.path)" :href="onlyOneChild.path" target="blank">
apple
<a :href="onlyOneChild.path" target="_blank" @click="clickLink(onlyOneChild.path,$event)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
</el-menu-item>
</a>
<router-link v-else :to="resolvePath(onlyOneChild.path)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
</el-menu-item>
</router-link>
</template>
<el-submenu v-else :index="item.name||item.path">
@ -29,11 +23,11 @@
:base-path="resolvePath(child.path)"
class="nest-menu"/>
<router-link v-else :to="resolvePath(child.path)" :key="child.name">
<a v-else :href="child.path" :key="child.name" target="_blank" @click="clickLink(child.path,$event)">
<el-menu-item :index="resolvePath(child.path)">
<item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
</el-menu-item>
</router-link>
</a>
</template>
</el-submenu>
@ -89,6 +83,13 @@ export default {
},
isExternalLink(routePath) {
return validateURL(routePath)
},
clickLink(routePath, e) {
if (!this.isExternalLink(routePath)) {
e.preventDefault()
const path = this.resolvePath(routePath)
this.$router.push(path)
}
}
}
}