定义全局loding
This commit is contained in:
22
src/App.vue
22
src/App.vue
@@ -1,9 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<RouteCache />
|
<RouteCache />
|
||||||
|
<div id="loading" v-if="!loading">
|
||||||
|
<van-loading size="10rem" color="#0094ff"/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import RouteCache from '@/components/RouteCache.vue'
|
import RouteCache from '@/components/RouteCache.vue'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { useOverallStore } from '@/stores'
|
||||||
|
|
||||||
|
const overallStore = useOverallStore()
|
||||||
|
const loading = computed(() => overallStore.loading)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@@ -41,4 +49,16 @@ import RouteCache from '@/components/RouteCache.vue'
|
|||||||
}
|
}
|
||||||
/* touch-action: none; */
|
/* touch-action: none; */
|
||||||
}
|
}
|
||||||
|
#loading {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 999999999;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.3);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import 'vant/lib/index.css'
|
|||||||
import { Locale } from 'vant';
|
import { Locale } from 'vant';
|
||||||
import enUS from 'vant/es/locale/lang/en-US';
|
import enUS from 'vant/es/locale/lang/en-US';
|
||||||
Locale.use('en-US', enUS);
|
Locale.use('en-US', enUS);
|
||||||
|
import { Loading } from 'vant';
|
||||||
|
|
||||||
|
|
||||||
import flexible from "./utils/flexible.js";
|
import flexible from "./utils/flexible.js";
|
||||||
@@ -32,6 +33,7 @@ document.addEventListener('touchend', function(event) {
|
|||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
app.use(router)
|
app.use(router)
|
||||||
.use(store)
|
.use(store)
|
||||||
|
.use(Loading)
|
||||||
.component("SvgIcon", SvgIcon)
|
.component("SvgIcon", SvgIcon)
|
||||||
.mount('#app')
|
.mount('#app')
|
||||||
|
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ const store = createPinia()
|
|||||||
// 使用持久化插件(全局持久化)
|
// 使用持久化插件(全局持久化)
|
||||||
store.use(createPersistedState())
|
store.use(createPersistedState())
|
||||||
export default store
|
export default store
|
||||||
export * from './modules/generate'
|
export * from './modules/generate'
|
||||||
|
export * from './modules/overall'
|
||||||
|
|||||||
19
src/stores/modules/overall.ts
Normal file
19
src/stores/modules/overall.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// 每一个存储的模块,命名规则use开头,store结尾
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
export const useOverallStore = defineStore({
|
||||||
|
id: 'overall', // 必须指明唯一的pinia仓库的id
|
||||||
|
state: () => {
|
||||||
|
return {
|
||||||
|
loading:false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getters: {
|
||||||
|
// doubleCount: (state) => state.num * 2
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
// 全局loading
|
||||||
|
setLoading(data:boolean){
|
||||||
|
this.loading = data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user