vue h5打点——记录页面停留时间

214 阅读1分钟
const startTime = ref(0);

const pageChange = () => {
    document.addEventListener("visibilitychange", () => {
        if (document.hidden) {
            let timeDiff = Date.now() - startTime.value;
            打点的方法("方法名", timeDiff);
        }

    });
};
onMounted(() => {
     startTime.value = Date.now();
     if (checkApp()) {
        pageChange()
     }
});

// checkApp方法见另一篇笔记,utils.js内,判断是否为app内