Monitor performance metrics with v-performance directive
Use Case: Monitor performance marks and measures using PerformanceObserver API.
Hint: Click the buttons to create performance marks and measures!
// Performance observer with v-performance directive <div v-performance="onPerformance"> <button @click="createMark">Create Mark</button> </div> methods: { onPerformance(entries, observer, options, $ctx) { const entryList = entries.getEntries(); entryList.forEach(entry => { console.log(`${entry.name}: ${entry.duration}ms`); }); // Access dropped entries count if available if (options?.droppedEntriesCount) { console.log(`Dropped: ${options.droppedEntriesCount}`); } }, createMark() { performance.mark(`mark-${Date.now()}`); } }
Use Case: Configure PerformanceObserver with custom options using :options.performance attribute.
Hint: This example only observes 'measure' entries!
// Custom entry types with :options.performance <div v-performance="onMeasurePerformance" :options.performance="measureOptions"> Observing only measures </div> data: { measureOptions: { entryTypes: ['measure'] } }, methods: { onMeasurePerformance(entries, observer, options, $ctx) { const measures = entries.getEntries(); measures.forEach(measure => { console.log(`Measure: ${measure.name}`); }); } }
// Handler signature onPerformance(entries: PerformanceObserverEntryList, observer: PerformanceObserver, options: { droppedEntriesCount?: number }, $ctx: LifecycleContext) { // entries.getEntries() - array of performance entries // entries.getEntriesByType(type) - filter by type // entries.getEntriesByName(name) - filter by name // options?.droppedEntriesCount - number of dropped entries // $ctx.element - DOM element // $ctx.vnode - VNode instance // $ctx.userData - Proxy-free storage } // Options format (PerformanceObserverInit) { entryTypes: ['mark', 'measure'], // array of entry types to observe type: 'navigation', // single entry type (alternative to entryTypes) buffered: true // include buffered entries }