2025-02-14 09:47:01 +08:00
|
|
|
import {Controller} from "@hotwired/stimulus"
|
|
|
|
|
|
|
|
export default class extends Controller {
|
|
|
|
static targets = ["timer"]
|
|
|
|
|
|
|
|
connect() {
|
|
|
|
// 记录页面加载开始的时间
|
|
|
|
const startTime = performance.now();
|
|
|
|
|
|
|
|
// 监听页面加载完成事件
|
|
|
|
window.addEventListener('load', () => {
|
|
|
|
const endTime = performance.now();
|
|
|
|
const loadTime = endTime - startTime;
|
|
|
|
// 更新显示
|
2025-02-14 11:09:33 +08:00
|
|
|
this.timerTarget.textContent = Math.ceil( loadTime );
|
2025-02-14 09:47:01 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|