index.js 961 B

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