antd vue 全局配置loading

1.在app.vue组件注入

//在template中写入
<div id="app">
      <a-spin
        v-bind="loadingProps"
      >
        <router-view />
      </a-spin>
    </div>
//在代码中写入
	import Vue from "vue";
	data () {
	    return {
	      loadingProps: {
	        spinning: false
	      }
	    }
	  },
	  beforeCreate () {
	    Vue.prototype.$app = this
	  }

2.在main.js将函数挂在在vue上 做了个传boolean的简易传值; 再做了个对象类型的校验/兼容,防止外面乱传参数。

Vue.prototype.$setLoading = function (props) {
  if (typeof props === 'boolean') props = { spinning: props }
  if (Object.prototype.toString.call(props) !== '[object Object]') props = {}
  this.$app.loadingProps = {
    tip: '加载中...',
    ...props
  }
}

3.在vue、js中调用

//在vue中调用
this.$setLoading(true)
this.$setLoading(false)//关闭loading
this.$setLoading({
  spinning: true,
   tip: '请稍等'
})
//在js中调用
import Vue from 'vue'
Vue.prototype.$setLoading(true)

你可能感兴趣的:(Ant,Design,of,Vue,vue.js,javascript,前端)