From b0bd91cd0fa11dcc94a402733f4e9b1ec647141b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Tue, 9 Oct 2018 14:10:43 +0800 Subject: [PATCH] add set tagsview title demo (#1167) --- src/utils/i18n.js | 4 +++- src/views/example/components/ArticleDetail.vue | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/utils/i18n.js b/src/utils/i18n.js index 0cb5e253..76be5a4e 100644 --- a/src/utils/i18n.js +++ b/src/utils/i18n.js @@ -1,9 +1,11 @@ // translate router.meta.title, be used in breadcrumb sidebar tagsview export function generateTitle(title) { const hasKey = this.$te('route.' + title) - const translatedTitle = this.$t('route.' + title) // $t :this method from vue-i18n, inject in @/lang/index.js if (hasKey) { + // $t :this method from vue-i18n, inject in @/lang/index.js + const translatedTitle = this.$t('route.' + title) + return translatedTitle } return title diff --git a/src/views/example/components/ArticleDetail.vue b/src/views/example/components/ArticleDetail.vue index c7ec1eb0..4e3dca2c 100644 --- a/src/views/example/components/ArticleDetail.vue +++ b/src/views/example/components/ArticleDetail.vue @@ -149,6 +149,9 @@ export default { computed: { contentShortLength() { return this.postForm.content_short.length + }, + lang() { + return this.$store.getters.language } }, created() { @@ -166,10 +169,18 @@ export default { // Just for test this.postForm.title += ` Article Id:${this.postForm.id}` this.postForm.content_short += ` Article Id:${this.postForm.id}` + + // Set tagsview title + this.setTagsViewTitle() }).catch(err => { console.log(err) }) }, + setTagsViewTitle() { + const title = this.lang === 'zh' ? '编辑文章' : 'Edit Article' + const route = Object.assign({}, this.$route, { title: `${title}-${this.postForm.id}` }) + this.$store.dispatch('updateVisitedView', route) + }, submitForm() { this.postForm.display_time = parseInt(this.display_time / 1000) console.log(this.postForm)