fix:levelbar&&tabsview bug

This commit is contained in:
Pan 2017-11-01 17:55:11 +08:00
parent 8211016078
commit aaf24b4654
4 changed files with 20 additions and 13 deletions

View file

@ -21,7 +21,8 @@ const app = {
if (state.visitedViews.some(v => v.path === view.path)) return
state.visitedViews.push({
name: view.name,
path: view.path
path: view.path,
title: view.meta.title || 'no-name'
})
if (!view.meta.noCache) {
state.cachedViews.push(view.name)

View file

@ -5,7 +5,7 @@
<sticky :className="'sub-navbar '+postForm.status">
<template v-if="fetchSuccess">
<router-link style="margin-right:15px;" v-show='isEdit' :to="{ path:'create'}">
<router-link style="margin-right:15px;" v-show='isEdit' :to="{ path:'create-form'}">
<el-button type="info">创建form</el-button>
</router-link>

View file

@ -20,6 +20,10 @@ export default {
methods: {
getBreadcrumb() {
let matched = this.$route.matched.filter(item => item.name)
if (matched.length === 0) {
this.levelList = [{ path: '/', meta: { title: '首页' }}]
return
}
const first = matched[0]
if (first && (first.name !== '首页' || first.path !== '')) {
matched = [{ path: '/', meta: { title: '首页' }}].concat(matched)

View file

@ -1,8 +1,7 @@
<template>
<scroll-pane class='tabs-view-container'>
<router-link class="tabs-view-item" :class="isActive(tag.path)?'active':''" v-for="tag in Array.from(visitedViews)" :to="tag.path"
:key="tag.path">
{{tag.name}}
<router-link class="tabs-view-item" :class="isActive(tag)?'active':''" v-for="tag in Array.from(visitedViews)" :to="tag.path" :key="tag.path">
{{tag.title}}
<span class='el-icon-close' @click='closeViewTabs(tag,$event)'></span>
</router-link>
</scroll-pane>
@ -20,7 +19,7 @@ export default {
}
},
mounted() {
this.$store.dispatch('addVisitedViews', this.generateRoute())
this.addViewTabs()
},
methods: {
closeViewTabs(view, $event) {
@ -37,17 +36,20 @@ export default {
$event.preventDefault()
},
generateRoute() {
if (this.$route.matched[this.$route.matched.length - 1].name) {
return this.$route.matched[this.$route.matched.length - 1]
if (this.$route.name) {
return this.$route
}
this.$route.matched[0].path = '/'
return this.$route.matched[0]
return false
},
addViewTabs() {
this.$store.dispatch('addVisitedViews', this.generateRoute())
const route = this.generateRoute()
if (!route) {
return false
}
this.$store.dispatch('addVisitedViews', route)
},
isActive(path) {
return path === this.$route.path
isActive(route) {
return route.path === this.$route.path || route.name === this.$route.name
}
},