vuex Loding加载..

本文介绍如何使用Vuex进行加载状态的管理,包括定义状态、更新状态的方法以及如何在组件中展示加载状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

技术栈:vuex,mapActions, mapState

先在vuex的状态管理里定义好loding状态,以及加载文字

import Vue from 'vue';
import Vuex from 'vuex';
import router from '../router'

Vue.use(Vuex);

const store = new Vuex.Store({

  modules: {
    
    },
  state: {  

    // 加载loding
    loading: {
      status:false,
      text:''
    },

  },

  mutations: {
    
    // 修改loding状态
    updateLoadingStatus(state, status) {
      state.loading.status = status.status;
      state.loading.text = status.text;
    },
  },

  actions: {

    // 控制loding
    startLoding({state, commit},status){

      commit('updateLoadingStatus', status)
    },

  }
});

export default store;

定义好loding加载状态,那么在页面引入loding组件,我用vux组件

<loading v-model="loading.status" :text="loading.text"></loading>
import { Loading } from 'vux'
  components: {
    Loading,
  },

需要操作

import { mapActions, mapState } from 'vuex'
import { Loading } from 'vux'

export default {
  components: {
    Loading,
  },
  computed: {
    ...mapState({
      loading: state => state.loading,
    })
  },

  created() {
    this.show();
  },

  methods:{

    ...mapActions(['startLoding',]),

    show(){
        this.startLoding({status: true, text: '加载..'})
        
    },
    up(){
        this.startLoding({status: false, text: '加载..'})
    }
  }
}

搞定

1125211-20170915004104610-512808277.png

转载于:https://www.cnblogs.com/liangfengbo/p/7524175.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值