Install introduced
import ElementUI from 'element-ui'
import { Loading } from 'element-ui'
The method defines a loading opening on the prototype chain vue
= Vue.prototype.openLoading function () { const loading = the this $ loading ({. // declare a loading objects Lock: to true , // whether the lock screen text: 'Loading ...', // loading animation characters Spinner: 'EL-icon-loading', // loading introduced by the icon background: 'RGBA (0, 0, 0, 0.3)', // background color target: '.sub-main', // needs to be masked regional body: to true , CustomClass:'mask' // mask layer new class name }) the setTimeout ( function () { // set a timer, turn off automatically after a timeout mask layer 5S, if the request fails to avoid the problem, there has been a mask layer loading. Close (); // Close mask layer }, 5000 ) return loading; }
Start request interface is a call to change the method, because we are the direct method on the prototype chain VUE definition, so we can direct this call
const rLoading = this.openLoading();
After the successful execution of the closing operation of the request:
rLoading.close();