From 62dc6a7a2e26bd951da320a7f3824efbe4f0b333 Mon Sep 17 00:00:00 2001 From: mxie <15623530290@163.com> Date: Tue, 19 Jun 2018 14:28:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=BB=98=E8=AE=A4=E8=AF=AD=E8=A8=80,?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mixins/locale.js | 30 ++++++++++++++++-------------- test/index.spec.js | 6 +----- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/mixins/locale.js b/src/mixins/locale.js index 3aed378..56cd614 100644 --- a/src/mixins/locale.js +++ b/src/mixins/locale.js @@ -1,3 +1,6 @@ +import Languages from '@/locale/languages' + +const defaultLang = Languages.zh export default { methods: { @@ -10,21 +13,20 @@ export default { name = component.$options.name } } - if (component && component.language) { - const arr = path.split('.') - let current = component.language - let value - for (let i = 0, len = arr.length; i < len; i++) { - const prop = arr[i] - value = current[prop] - if (i === len - 1) { - return value - } - if (!value) { - return '' - } - current = value + const lang = component && component.language || defaultLang + const arr = path.split('.') + let current = lang + let value + for (let i = 0, len = arr.length; i < len; i++) { + const prop = arr[i] + value = current[prop] + if (i === len - 1) { + return value } + if (!value) { + return '' + } + current = value } return '' } diff --git a/test/index.spec.js b/test/index.spec.js index fb31a64..cba972c 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,15 +1,11 @@ import Vue from 'vue' import { mount, shallowMount } from '@vue/test-utils' -import { use } from '../src/locale/index' import DatePicker from '../src/index.vue' import CalendarPanel from '../src/calendar.vue' - import DatePanel from '../src/panel/date' import TimePanel from '../src/panel/time' import YearPanel from '../src/panel/year' -use('zh') - let wrapper afterEach(() => { @@ -191,7 +187,7 @@ describe('datepicker', () => { expect(el.getAttribute('placeholder')).toBe('hehe') }) - it.only('prop: lang', () => { + it('prop: lang', () => { wrapper = mount(DatePicker, { propsData: { lang: 'en',