From d58dafeda9f0bed3075aa45c997a29dfa8ed8e50 Mon Sep 17 00:00:00 2001 From: iczer <1126263215@qq.com> Date: Wed, 24 Jun 2020 16:34:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20new=20custom=20plugin=20of=20Vue;=20:st?= =?UTF-8?q?ar2:=20=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=96=B0=E5=A2=9EVue?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8F=92=E4=BB=B6=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 2 ++ src/plugins/i18n-extend.js | 21 +++++++++++++++++++++ src/plugins/index.js | 7 +++++++ 3 files changed, 30 insertions(+) create mode 100644 src/plugins/i18n-extend.js create mode 100644 src/plugins/index.js diff --git a/src/main.js b/src/main.js index ef4c5d2..ef308e6 100644 --- a/src/main.js +++ b/src/main.js @@ -10,12 +10,14 @@ import store from './store' import PouchDB from 'pouchdb' import 'animate.css/source/animate.css' import VueI18n from 'vue-i18n' +import Plugins from '@/plugins' Vue.prototype.$axios = axios Vue.config.productionTip = false Vue.use(Viser) Vue.use(Antd) Vue.use(VueI18n) +Vue.use(Plugins) const i18n = new VueI18n({ locale: 'CN', diff --git a/src/plugins/i18n-extend.js b/src/plugins/i18n-extend.js new file mode 100644 index 0000000..ea4ac90 --- /dev/null +++ b/src/plugins/i18n-extend.js @@ -0,0 +1,21 @@ +const VueI18nPlugin = { + install: function (Vue) { + Vue.mixin({ + methods: { + $ta(syntaxKey) { + let keys = syntaxKey.split('|') + let message = '' + let _this = this + keys.forEach(key => { + message += _this.$t(key) + }) + if (keys.length > 0) { + message = message.charAt(0).toUpperCase() + message.toLowerCase().substring(1) + } + return message + } + } + }) + } +} +export default VueI18nPlugin diff --git a/src/plugins/index.js b/src/plugins/index.js new file mode 100644 index 0000000..0b04285 --- /dev/null +++ b/src/plugins/index.js @@ -0,0 +1,7 @@ +import VueI18nPlugin from '@/plugins/i18n-extend'; +const Plugins = { + install: function (Vue) { + Vue.use(VueI18nPlugin) + } +} +export default Plugins