总结vue页面刷新的几种方法

1.this. r o u t e r . g o ( 0 ) 这 种 方 法 页 面 会 一 瞬 间 的 白 屏 . 2. l o c a t i o n . r e l o a d ( ) 这 种 也 是 一 样 , 画 面 一 闪 . 3. 跳 转 空 白 页 再 跳 回 原 页 面 在 需 要 页 面 刷 新 的 地 方 写 上 : t h i s . router.go(0) 这种方法页面会一瞬间的白屏. 2.location.reload() 这种也是一样,画面一闪. 3.跳转空白页再跳回原页面 在需要页面刷新的地方写上:this. router.go(0).2.location.reload().3.this.router.push(’/emptyPage’),跳转到一个空白页。在emptyPage.vue里beforeRouteEnter 钩子里控制页面跳转,从而达到刷新的效果
beforeRouteEnter (to, from, next) {
next(vm => {
vm.KaTeX parse error: Expected 'EOF', got '}' at position 33: …om.path) }̲) }。 4.控制<route…nextTick(function () {
this.isRouterAlive = true
})
这种方法从画面上是看不出破绽的。也可以搭配provide、inject使用。例如:

export default { name: "app", data() { return { isRouterAlive: true, urlParse: urlParse }; }, provide() { return { reload: this.reload }; }, methods: { reload() { this.isRouterAlive = false; this.$nextTick(function() { this.isRouterAlive = true; }); } }, };

---------网上的帖子。业务需求是home页面刷新,重新渲染数据,如果用方法5的话。刷新会导致,弹窗和menu部分消失。所以不用刷新页面,只重新调用接口。从而实现数据的重新渲染。这个没有实操,现存着,用的时候做参考。
1、给Vue的原型上添加一个bus属性
main.js:Vue.prototype.KaTeX parse error: Expected '}', got 'EOF' at end of input: …ofile () {this.bus.KaTeX parse error: Expected 'EOF', got '}' at position 15: emit('change')}̲ 3、页面1里监听如果执行了操…bus.$on(‘change’, ()=> {
this.doSomething()
})
},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值