前端刷新页面的方法
前端刷新页面的方法reload() 方法reload() 方法用于刷新当前文档,类似于浏览器上的刷新页面按钮window.location.reload()replace() 方法replace() 方法可用一个新文档取代当前文档window.location.replace("http://www.runoob.com")页面自动刷新其中5指每隔5秒刷新一次页面<meta http-equ
·
前端刷新页面的方法
reload() 方法
reload() 方法用于刷新当前文档,类似于浏览器上的刷新页面按钮
window.location.reload()
replace() 方法
replace() 方法可用一个新文档取代当前文档
window.location.replace("http://www.runoob.com")
页面自动刷新
其中5指每隔5秒刷新一次页面
<meta http-equiv="refresh" content="5">
Vue-Router路由跳转
this.$router.go(0)
Vue依赖注入
<template>
<div id="app">
<router-view v-if="isRouterAlive"></router-view>
</div>
</template>
<script>
export default {
name: 'App',
// 父组件中通过provide来提供变量,在子组件中通过inject来注入变量
provide () {
return {
reload: this.reload
}
},
data() {
return{
//控制视图是否显示的变量
isRouterAlive: true
}
},
methods: {
reload () {
//先关闭
this.isRouterAlive = false
this.$nextTick(function () {
//再打开
this.isRouterAlive = true
})
}
},
}
</script>
需要刷新页面的组件中注入App里的reload方法
export default {
inject:['reload'],
data () {
return {}
}
}
在需要刷新页面的代码块中使用
this.reload()
参考文章
更多推荐
已为社区贡献1条内容
所有评论(0)