为了账号安全,请及时绑定邮箱和手机立即绑定

angular 中 performance.navigation.type 的替代品是什么?

angular 中 performance.navigation.type 的替代品是什么?

慕哥6287543 2021-12-12 15:30:33
我有这个代码是为了知道页面是否被用户重新加载,不幸的是已被弃用。我想知道 angular 是否有这种方法。if (performance.navigation.type === 1) {   console.log('is refreshed')}if (performance.navigation.type === 0) {   console.log('the user is arrived')}  
查看完整描述

3 回答

?
HUH函数

TA贡献1836条经验 获得超4个赞

不是 Angular 特有的,但是这个 API 已经被PerformanceNavigationTiming取代,它也有一个type属性,但它返回一个字符串而不是数字代码。


但是我只是注意到 Chrome 不会为 iframe 公开它,它总是会输出"navigate".


以下代码段在 Chrome 中不起作用,请在外部视图中尝试使用此 plnkr。


const entries = performance.getEntriesByType("navigation");


console.log( entries.map( nav => nav.type ) );


rel.onclick = e => location.reload();

<button type="button" id="rel">reload</button>

<a href="404">go to 404 (come back with your browser's back button)</a>


查看完整回答
反对 回复 2021-12-12
?
开满天机

TA贡献1786条经验 获得超13个赞

performance.navigation已弃用。要获取导航类型,您可以使用getEntriesByType


例子


console.log(performance.getEntriesByType("navigation")[0].type)

该type值可以是


enum NavigationType {

    "navigate",

    "reload",

    "back_forward",

    "prerender"

};

查看更多:https : //w3c.github.io/navigation-timing/#sec-performance-navigation-types


查看完整回答
反对 回复 2021-12-12
?
MYYA

TA贡献1868条经验 获得超4个赞

我想添加运行:

performance.getEntriesByType("navigation");

在 Safari 中返回一个空数组


查看完整回答
反对 回复 2021-12-12
  • 3 回答
  • 0 关注
  • 1735 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号