vue功能之“loading加载优化“

一、新建组件写入

<template>
  <div class="loading">
      <img src="/imgs/loading-svg/loading-bars.svg" alt="">
  </div>
</template>

<script>
export default {
    name:'loading'
}
</script>

<style lang='scss'>
.loading{
    height: 80px;
    line-height: 80px;
    text-align: center;
    padding: 30px 0;
    img{
        height: 100%;
    }
}
</style>

二、 使用


<template>
  <div class="order-list">
    <div class="wrapper">
      <div class="container">
        <div class="order-box">
          <loading v-if="loading"></loading>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import Loading from './../components/Loading'
  export default{
    name:'order-list',//orderList订单详情
    components:{
      Loading,
    },

    data(){
     return{
       list:[],//商品列表
       loading:true,//是否显示懒加载
       pageSize:10,//动态绑定的-每页显示条目个数
       total:0,//总条目数
       pageNum:1,//能够自动识别-显示几列-
       busy:false,//默认不触发滚动
       showNextPage:false,//是否显示-加载更多
     }
    },
    mounted(){
      this.getOrderList()
    },
    methods:{
     
      getOrderList(){//获取列表信息
       this.loading = true
       this.busy = true
        this.$axios.get('/orders',
        {
          params:{
            pageSize:10,
            pageNum:this.pageNum
          }
        }).then((res)=>{
          this.loading = false
          this.list = this.list.concat(res.list)//数组累加
          this.total = res.total
          this.showNextPage = res.hasNextPage
          this.busy = false
        }).catch(()=>{
          this.loading = false
          
        })
      },
    }
  }
</script>

三、效果展示

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值