vue实现页面刷新以及局部刷新的方法

1、利用Vue里面的provide+inject组合,实现全页面刷新

通过在APP页面进行demo进行刷新,不会像前两种那样出现短暂的闪烁效果,提升用户体验,通常可以使用这种方式

(1)在APP页面中写入下面代码

<template>
  <div id="app">
    <router-view v-if="isShow"/>
  </div>
</template>

<script>
export default {
  name: 'App',
  provide(){
    return{
      reload:this.reload
    }
  },
  data(){
    return{
      isShow:true
    }
  },
  methods:{
    reload(){
      this.isShow=false;
      this.$nextTick(()=>{
        this.isShow=true
      })
    }
  }
}
</script>

(2)在需要刷新的页面进行引入并使用

<template>
  <div>
      <div class="header">
          <button @click="update()">刷新页面</button>
      </div>
  </div>
</template>

<script>
export default {
data(){
  return{

  }
},
inject:[
  'reload'
],
methods:{
  update(){
    this.reload()
    console.log('刷新页面')
  }
}
}
</script>

2、实现页面中局部刷新

(1)定义局部刷新的方法 reload:

<template>
	<div v-if="isShow" class="sub-wrapper">
      <PieChart :chartData="list" />
  	</div>
</template>
<script>
export default{
	data(){
		return{
			isShow: true,
		}
	},
	methods: {
		reload () {//局部刷新
			this.isShow = false;
			this.$nextTick(() => {
				this.isShow = true
			})
		},
	}
}
</script>

(2)在需要执行局部刷新的方法中进行调用

Refresh() {
  this.reload()
  WorkorderStateReport().then((res) => {
    this.loading = true;
    if (res.data.length > 0) {
      this.list = res.data;
    }
  });
},

参考链接:
1、https://blog.csdn.net/qq_32555123/article/details/124627017
2、https://www.jb51.net/article/233809.htm

  • 9
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值