mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 19:24:16 +00:00
[Improvement] Support Vue.use to register a component (#401)
This commit is contained in:
@@ -1,29 +1,10 @@
|
||||
import Vue from 'vue';
|
||||
import { get, camelize } from '../utils';
|
||||
import deepAssign from '../utils/deep-assign';
|
||||
import defaultMessages from './lang/zh-CN';
|
||||
|
||||
// component mixin
|
||||
const i18n = {
|
||||
computed: {
|
||||
$t() {
|
||||
const { name } = this.$options;
|
||||
const prefix = name ? camelize(name) + '.' : '';
|
||||
const messages = this.$vantMessages[this.$vantLang];
|
||||
|
||||
return (path, ...args) => {
|
||||
const message = get(messages, prefix + path) || get(messages, path);
|
||||
return typeof message === 'function' ? message.apply(null, args) : message;
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const proto = Vue.prototype;
|
||||
const defaultLang = 'zh-CN';
|
||||
const locale = {
|
||||
i18n,
|
||||
|
||||
init() {
|
||||
Vue.util.defineReactive(proto, '$vantLang', defaultLang);
|
||||
Vue.util.defineReactive(proto, '$vantMessages', { [defaultLang]: defaultMessages });
|
||||
@@ -41,4 +22,3 @@ const locale = {
|
||||
|
||||
locale.init();
|
||||
export default locale;
|
||||
export { i18n };
|
||||
|
Reference in New Issue
Block a user