loading

import Vue from 'vue'
import Loading from './alp-loading'
let instance = null
function initLoading () {
  if (!instance) {
    let MyLoadingComponent = Vue.extend(Loading)
    instance = new MyLoadingComponent({
      el: document.createElement('section')
    })
    document.body.appendChild(instance.$el)
  }
  instance.showLoading = false
}

let loading = {
  show (opt) {
    instance.$data.value = opt || '加载中...'
    instance.showLoading = true
    document.body.appendChild(instance.$el)
  },
  hide () {
    instance.showLoading = false
  }
}

export default {
  install (_vue) {
    if (!_vue.$loading) {
      initLoading()
      _vue.prototype.$loading = loading
    }
  },
  show: loading.show,
  hide: loading.hide
}

你可能感兴趣的:(loading)