自定义组件 v-loading
通过指令方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <template> <div class = "loading-container" > <icon-sync class = "icon" spin /> </div> </template> <script lang= "ts" setup> import { IconSync } from '@arco-design/web-vue/es/icon' </script> <style lang= "less" scoped> .loading-container { position: absolute; top: 0; left: 0; z-index: 10; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.6); .icon { color: #409eff; font-size: 32px; } } </style> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import { DirectiveBinding, createApp } from 'vue' import Loading from './index.vue' const toggle = (value: boolean, el: any) => { if (value) { el.appendChild(el.instance.$el) } else { const container = el.querySelector( '.loading-container' ) if (container) { el.removeChild(container) } } } export default { mounted(el: any, binding: DirectiveBinding) { const app = createApp(Loading) const instance = app.mount(document.createElement( 'div' )) el.instance = instance el.style.position = 'relative' toggle(binding.value, el) }, updated(el: HTMLElement, binding: DirectiveBinding) { console.log(binding.value) toggle(binding.value, el) } } |
组件包裹的方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <template> <a-spin :loading= "loading" style= "display: inherit" > <slot></slot> </a-spin> </template> <script lang= "tsx" setup> import { computed } from 'vue' import { loadingStore } from '@/store/modules/loading' const storeLoading = loadingStore() as any const props = defineProps({ loadingName: { type: String } }) const loading = computed(() => { const name = props.loadingName || 'loading' return storeLoading.$state[name] }) </script> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了