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

View file

@ -1,7 +1,7 @@
<template>
<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">
{{$t('route.'+tag.title)}}
{{generateTitle(tag.title)}}
<span class='el-icon-close' @click='closeViewTags(tag,$event)'></span>
</router-link>
</scroll-pane>
@ -9,6 +9,7 @@
<script>
import ScrollPane from '@/components/ScrollPane'
import { generateTitle } from '@/utils/i18n'
export default {
components: { ScrollPane },
@ -21,6 +22,7 @@ export default {
this.addViewTags()
},
methods: {
generateTitle,
closeViewTags(view, $event) {
this.$store.dispatch('delVisitedViews', view).then((views) => {
if (this.isActive(view)) {
@ -61,7 +63,6 @@ export default {
}
})
}
},
watch: {
$route() {