perf(i18n): add generateTitle to utils

This commit is contained in:
Pan 2017-12-06 14:18:28 +08:00
parent d09923ff4f
commit acebaeae0c
4 changed files with 12 additions and 8 deletions

View File

@ -10,6 +10,8 @@
</template> </template>
<script> <script>
import { generateTitle } from '@/utils/i18n'
export default { export default {
created() { created() {
this.getBreadcrumb() this.getBreadcrumb()
@ -25,6 +27,7 @@ export default {
} }
}, },
methods: { methods: {
generateTitle,
getBreadcrumb() { getBreadcrumb() {
let matched = this.$route.matched.filter(item => item.name) let matched = this.$route.matched.filter(item => item.name)
const first = matched[0] const first = matched[0]
@ -32,9 +35,6 @@ export default {
matched = [{ path: '/dashboard', meta: { title: 'dashboard' }}].concat(matched) matched = [{ path: '/dashboard', meta: { title: 'dashboard' }}].concat(matched)
} }
this.levelList = matched this.levelList = matched
},
generateTitle(title) {
return this.$t('route.' + title)
} }
} }
} }

3
src/utils/i18n.js Normal file
View File

@ -0,0 +1,3 @@
export function generateTitle(title) {
return this.$t('route.' + title) // $t :this method from vue-i18n ,inject in @/lang/index.js
}

View File

@ -32,6 +32,8 @@
</template> </template>
<script> <script>
import { generateTitle } from '@/utils/i18n'
export default { export default {
name: 'SidebarItem', name: 'SidebarItem',
props: { props: {
@ -40,9 +42,7 @@ export default {
} }
}, },
methods: { methods: {
generateTitle(title) { generateTitle
return this.$t('route.' + title)
}
} }
} }
</script> </script>

View File

@ -1,7 +1,7 @@
<template> <template>
<scroll-pane class='tags-view-container' ref='scrollPane'> <scroll-pane class='tags-view-container' ref='scrollPane'>
<router-link ref='tag' class="tags-view-item" :class="isActive(tag)?'active':''" v-for="tag in Array.from(visitedViews)" :to="tag.path":key="tag.path"> <router-link ref='tag' class="tags-view-item" :class="isActive(tag)?'active':''" v-for="tag in Array.from(visitedViews)" :to="tag.path":key="tag.path">
{{$t('route.'+tag.title)}} {{generateTitle(tag.title)}}
<span class='el-icon-close' @click='closeViewTags(tag,$event)'></span> <span class='el-icon-close' @click='closeViewTags(tag,$event)'></span>
</router-link> </router-link>
</scroll-pane> </scroll-pane>
@ -9,6 +9,7 @@
<script> <script>
import ScrollPane from '@/components/ScrollPane' import ScrollPane from '@/components/ScrollPane'
import { generateTitle } from '@/utils/i18n'
export default { export default {
components: { ScrollPane }, components: { ScrollPane },
@ -21,6 +22,7 @@ export default {
this.addViewTags() this.addViewTags()
}, },
methods: { methods: {
generateTitle,
closeViewTags(view, $event) { closeViewTags(view, $event) {
this.$store.dispatch('delVisitedViews', view).then((views) => { this.$store.dispatch('delVisitedViews', view).then((views) => {
if (this.isActive(view)) { if (this.isActive(view)) {
@ -61,7 +63,6 @@ export default {
} }
}) })
} }
}, },
watch: { watch: {
$route() { $route() {