vue封裝全局的Loading問題
更新時間:2026年05月24日 10:41:22 作者:想要飛翔的pig
本文詳細介紹了在Vue項目中實現(xiàn)加載動畫的方法,通過在app.vue注入樣式、封裝js文件及在main.js掛載,最后在頁面調(diào)用觸發(fā)的具體步驟,為開發(fā)者提供實用指南
一、在app.vue組件注入loading樣式
<template>
<meg-loading
:tip="centitle"
:indicator="indicator"
:spinning="antLoading"
style="background-color: rgba(0, 0, 0, 0.6)"
>
</meg-loading>
</template>
<script>
import { mapState } from "vuex";
export default {
name: "MegCubeLayout",
data() {
return {
indicator: <meg-icon name="megui-loading2"></meg-icon>,
};
},
computed: {
...mapState("megCube/container", ["antLoading", "centitle"]),
},
};
二、封裝的js文件 globalMethod.js
export const showLoading = function (flag, msg) {
if (msg) {
this.$store.state.megCube.container.centitle = msg
} else {
this.$store.state.megCube.container.centitle = '加載中...'
}
if (flag) {
this.$store.state.megCube.container.antLoading = flag
} else {
this.$store.state.megCube.container.antLoading = false
}
}
三、在main.js掛載
import { showLoading } from './common/globalMethod'
Vue.prototype.$showLoading = showLoading // 全局loading
四、vue頁面調(diào)用
- 觸發(fā):
this.$showLoading(true, '正在上傳中')
- 停止:
this.$showLoading(false)
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3實現(xiàn)跨頁面?zhèn)髦档膸追N常見方法
在Vue 3中,跨頁面?zhèn)髦悼梢酝ㄟ^多種方式實現(xiàn),具體選擇哪種方法取決于應(yīng)用的具體需求和頁面間的關(guān)系,本文列舉了幾種常見的跨頁面?zhèn)髦捣椒?感興趣的同學跟著小編來看看吧2024-04-04
利用Vue.js+Node.js+MongoDB實現(xiàn)一個博客系統(tǒng)(附源碼)
本文主要介紹了利用Vue.js+Node.js+MongoDB實現(xiàn)一個博客系統(tǒng),這個博客使用Vue做前端框架,Node+express做后端,數(shù)據(jù)庫使用的是MongoDB。實現(xiàn)了用戶注冊、用戶登錄、博客管理、文章編輯、標簽分類等功能,需要的朋友可以參考學習。2017-04-04
vue單頁面如何通過prerender-spa-plugin插件進行SEO優(yōu)化
這篇文章主要介紹了vue單頁面如何通過prerender-spa-plugin插件進行SEO優(yōu)化,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-05-05
Vue利用Web?Speech?API實現(xiàn)文字朗讀功能
在?Vue?頁面中實現(xiàn)文字朗讀(Text-to-Speech,TTS)可以通過瀏覽器的?Web?Speech?API?實現(xiàn),下面小編就來和大家簡單講講具體實現(xiàn)步驟吧2025-02-02

