import Stats from 'stats.js'; export default class StatsPanel{ stats: Stats; //监听器本身 constructor(parentId: string){ //parentId: 外部包装监听器的模块的id this.add(parentId); } add(parentId: string){//添加监听器 const root = document.getElementById(parentId); if (!root) return; if (this.stats) return; const tmpStats = new Stats(); tmpStats.showPanel(0); tmpStats.dom.style.position = 'relative' root.appendChild(tmpStats.dom); this.stats = tmpStats; } update(){//更新监听器(在页面刷新处调用) if(this.stats){ this.stats.update(); } } }