Vue 关于Loading组件的用法心得 记录一下

Vue 关于Loading组件的用法心得 记录一下

1.首先需要install一下VUEX,下为VUEX的写法

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
 
export default new Vuex.Store({
  state:{
    LOADING: false   
  },
  mutations:{
    showLoading(state){
      state.LOADING = true    
  },
    hideLoading (state){
      state.LOADING = false
  }
  },
  getters: {},
  actions: {}
})
  1. 再弄一个Loading组件 这里贴一个
  2. 这里面的CSS需要install一下 node-sass 才能呈现出效果
<template>
<div class="spinner">
     <div class="rect1"></div>
     <div class="rect2"></div>
     <div class="rect3"></div>
     <div class="rect4"></div>
     <div class="rect5"></div>
 </div>
</template>
<script>
export default {
    name: 'loading',
    data() {
        return {}
    }
}
</script>
<style scoped lang="scss">
.spinner {
  margin: 100px auto;
  width: 50px;
  height: 60px;
  text-align: center;
  font-size: 10px;
}
 
.spinner > div {
//   background-color: #67CF22;
background-color: #009688;
  height: 100%;
  width: 6px;
  display: inline-block;
   
  -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
  animation: stretchdelay 1.2s infinite ease-in-out;
}
 
.spinner .rect2 {
  -webkit-animation-delay: -1.1s;
  animation-delay: -1.1s;
}
 
.spinner .rect3 {
  -webkit-animation-delay: -1.0s;
  animation-delay: -1.0s;
}
 
.spinner .rect4 {
  -webkit-animation-delay: -0.9s;
  animation-delay: -0.9s;
}
 
.spinner .rect5 {
  -webkit-animation-delay: -0.8s;
  animation-delay: -0.8s;
}
 
@-webkit-keyframes stretchdelay {
  0%, 40%, 100% { -webkit-transform: scaleY(0.4) } 
  20% { -webkit-transform: scaleY(1.0) }
}
 
@keyframes stretchdelay {
  0%, 40%, 100% {
    transform: scaleY(0.4);
    -webkit-transform: scaleY(0.4);
  }  20% {
    transform: scaleY(1.0);
    -webkit-transform: scaleY(1.0);
  }
}
</style>

4.如果上面两个都搞定了 接下来 打开 main.js
写入以下两段代码 意思就是 引入上面那两个部分并使用它们

import store from './store/store'
import loading from './components/loading/loading.vue'

Vue.use(loading)
Vue.use(Vuex)

new Vue({
  el: '#app',
  store,     // 记得写上
  router,
  components: { App },
  template: '<App/>'
})

5.最后 找个文件引入就可以了

<template>
<div>
  <loading v-if='LOADING'></loading>  //引入的位置
  </div>
</template>

<script>
import loading from '../loading/loading.vue'  
import { mapState } from "vuex";
export default {
  name: "toot",
   computed: {  
    ...mapState(["LOADING"])
  },
    components:{     
         loading,
  }
  data() {
    return {}
  },
  methods: {
     getURL: function() {
       this.$store.commit('showLoading')  
    
       this.$store.commit('hideLoading')
      })
    }
  },
   Created(){
    this.getURL();   //创建后立刻调用上面那个方法
   },
};
</script>

小白一枚 研究许久 有感而发 如有不足 望其指出 有些地方参考了其他人的 如有雷同 纯属巧合
谢谢大家

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值