# 单例模式
# 目录结构
|-- src
|-- |-- widgets
|-- |-- | |--loading.js
1
2
3
2
3
# Loading
- 用法
<script> import { ServiceLoading } from '@/src/widgets/loading' ServiceLoading.show() ServiceLoading.hide() </script>
1
2
3
4
5
6
7 - 实现 (opens new window)
import Vue from 'vue' import { Loading } from 'element-ui' export class ServiceLoading { static instance = null static show (options) { this.instance = Loading.service(options) } static hide () { Vue.nextTick(() => { this.instance.close() }) } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16