懒羊羊
2024-01-31 e57a8990ae56f657a59c435a0613c5f7a8728003
提交 | 用户 | 时间
e57a89 1 import Dict from './Dict'
2 import { mergeOptions } from './DictOptions'
3
4 export default function(Vue, options) {
5   mergeOptions(options)
6   Vue.mixin({
7     data() {
8       if (this.$options === undefined || this.$options.dicts === undefined || this.$options.dicts === null) {
9         return {}
10       }
11       const dict = new Dict()
12       dict.owner = this
13       return {
14         dict
15       }
16     },
17     created() {
18       if (!(this.dict instanceof Dict)) {
19         return
20       }
21       options.onCreated && options.onCreated(this.dict)
22       this.dict.init(this.$options.dicts).then(() => {
23         options.onReady && options.onReady(this.dict)
24         this.$nextTick(() => {
25           this.$emit('dictReady', this.dict)
26           if (this.$options.methods && this.$options.methods.onDictReady instanceof Function) {
27             this.$options.methods.onDictReady.call(this, this.dict)
28           }
29         })
30       })
31     },
32   })
33 }