Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit 5ed69f8

Browse files
albert-zhangkazupon
authored andcommitted
⭐ new: $lang property for all component (#99) by @albert-zhang
1 parent 0d1bc1f commit 5ed69f8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

gitbook/api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,13 @@
191191

192192
- **Usage:**
193193
Check whether key path exists. In Vue instance, If not specified component locale, check with global locale. If you specified `lang`, check the locale of `lang`.
194+
195+
## Instance Properties
196+
197+
### $lang
198+
199+
- **Return**
200+
The lang you set via `Vue.config.lang`
201+
202+
- **Usage**
203+
You can do some complex things if you need. Note a good design should not rely on this too much.

src/extend.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,13 @@ export default function (Vue) {
232232
return found
233233
}
234234

235+
Vue.mixin({
236+
computed: {
237+
$lang () {
238+
return Vue.config.lang
239+
}
240+
}
241+
})
242+
235243
return Vue
236244
}

test/specs/component.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@ describe('component locales', () => {
7777
assert.equal(comp1.$t('fallback', 'ja'), 'this is fallback on component')
7878
})
7979
})
80+
81+
describe('$lang', () => {
82+
it('should be work', () => {
83+
const comp1 = vm.$children[0] // component1
84+
assert.equal(comp1.$lang, 'en')
85+
})
86+
})
8087
})

0 commit comments

Comments
 (0)