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',