[英]vue refresh the page only once
Is it possible to reload a page when it is created or mounted or something similar?是否可以在创建或安装页面时重新加载页面或类似的东西? let me explain, I would like that when a page is loaded, we must activate location.reload()
;让我解释一下,我希望在加载页面时,我们必须激活location.reload()
; but if I do it on created()
, or on mounted()
I get a loop loading.但是如果我在created()
或mounted()
上执行此操作,我会得到一个循环加载。 instead I would like to reload only the first time, so I enter that page and the page reloads only once.相反,我只想第一次重新加载,所以我进入该页面并且页面只重新加载一次。
I tried with:我试过:
created() {
if(this.reloaded == false) {
location.reload();
this.reloaded = true;
}
},
data() {
return {
reloaded: false,
};
},
Because you're reloading the page, you can't store the state within the Vue instance.因为您正在重新加载页面,所以不能将 state 存储在 Vue 实例中。 Instead, you can store it in local storage:相反,您可以将其存储在本地存储中:
export default {
created() {
const reloaded = localStorage.getItem('reloaded');
if (reloaded !== 'true') {
localStorage.setItem('reloaded', 'true');
location.reload();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.