在性能缓冲区中使用给定名称添加一个 name 为 name 的性能数据。
xhs.getPerformance().mark(name)
类型 | 默认值 | 必填 | 说明 |
---|---|---|---|
string | 无 | 是 | 期望标记的 name |
// 创建一些标记 xhs.getPerformance && xhs.getPerformance().mark("xhs-test"); xhs.getPerformance && xhs.getPerformance().mark("xhs-test"); xhs.getPerformance && xhs.getPerformance().mark("xhs-test-2"); xhs.getPerformance && xhs.getPerformance().mark("xhs-test-2"); xhs.getPerformance && xhs.getPerformance().mark("xhs-test-3"); xhs.getPerformance && xhs.getPerformance().mark("xhs-test-3"); // 获取所有的 PerformanceMark 条目 const allEntries = xhs.getPerformance && xhs.getPerformance().getEntriesByType("mark"); console.log(allEntries.length); // 6 // 获取所有的名为 "xhs-test" PerformanceMark 条目 const xhs-testEntries = xhs.getPerformance && xhs.getPerformance().getEntriesByName("xhs-test"); console.log(xhs-testEntries.length); // 2 // 删除所有标记。 xhs.getPerformance && xhs.getPerformance().clearMarks(); console.log(xhs.getPerformance && xhs.getPerformance().getEntriesByType("mark")); // 0
// 假设 FMP 依赖某个接口的数据,接口返回数据后 setData 更新页面后上报 FMP Page({ data: { pages: [], }, onLoad() { xhs.request({ url: `${developer_api_url}`, success: (res) => { this.setData( { pages: res.data, }, () => { // 统计 FMP xhs.getPerformance && xhs.getPerformance.mark("FMP"); } ); }, fail: (err) => {}, }); }, });