Skip to content

Commit b0bd91c

Browse files
authored
add set tagsview title demo (PanJiaChen#1167)
1 parent ae2754a commit b0bd91c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/utils/i18n.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// translate router.meta.title, be used in breadcrumb sidebar tagsview
22
export function generateTitle(title) {
33
const hasKey = this.$te('route.' + title)
4-
const translatedTitle = this.$t('route.' + title) // $t :this method from vue-i18n, inject in @/lang/index.js
54

65
if (hasKey) {
6+
// $t :this method from vue-i18n, inject in @/lang/index.js
7+
const translatedTitle = this.$t('route.' + title)
8+
79
return translatedTitle
810
}
911
return title

src/views/example/components/ArticleDetail.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ export default {
149149
computed: {
150150
contentShortLength() {
151151
return this.postForm.content_short.length
152+
},
153+
lang() {
154+
return this.$store.getters.language
152155
}
153156
},
154157
created() {
@@ -166,10 +169,18 @@ export default {
166169
// Just for test
167170
this.postForm.title += ` Article Id:${this.postForm.id}`
168171
this.postForm.content_short += ` Article Id:${this.postForm.id}`
172+
173+
// Set tagsview title
174+
this.setTagsViewTitle()
169175
}).catch(err => {
170176
console.log(err)
171177
})
172178
},
179+
setTagsViewTitle() {
180+
const title = this.lang === 'zh' ? '编辑文章' : 'Edit Article'
181+
const route = Object.assign({}, this.$route, { title: `${title}-${this.postForm.id}` })
182+
this.$store.dispatch('updateVisitedView', route)
183+
},
173184
submitForm() {
174185
this.postForm.display_time = parseInt(this.display_time / 1000)
175186
console.log(this.postForm)

0 commit comments

Comments
 (0)