JavaScript/vue.js/刷新页面
来自康健生活
< JavaScript | vue.js
无需重新加载页面或刷新dom
history.pushState
addHashToLocation(params) {
history.pushState(
{},
null,
this.$route.path + '#' + encodeURIComponent(params)
)
}
addHashToLocation('/my/new/path')
// main component
created() {
// event fire when pushState
this.$nuxt.$on('pushState', params => {
// do your logic with params
})
},
beforeDestroy() {
this.$nuxt.$off('pushState')
},
...
// Where there are history.pushState
this.$nuxt.$emit('pushState', params)
history.replaceState
点击页面刷新之前触发事件
onbeforeunload
事件在即将离开当前页面(刷新或关闭)时触发。
导航守卫
导航守卫主要用来通过跳转或取消的方式守卫导航。有多种机会植入路由导航过程中:全局的, 单个路由独享的, 或者组件级的。
No categories