Angular Konva 缓存教程
在 Angular 中使用 Konva
的缓存功能,可以通过 ng2-konva
库结合 cache
方法来提升性能。
有关所有属性和方法的完整列表,请参阅 Konva API 参考。
缓存示例
import { Component, ViewChild, AfterViewInit } from '@angular/core'; import { StageConfig } from 'konva/lib/Stage'; import { RectConfig } from 'konva/lib/shapes/Rect'; import { CoreShapeComponent, StageComponent, } from 'ng2-konva'; @Component({ selector: 'app-root', template: ` <ko-stage [config]="configStage"> <ko-layer> <ko-rect #rect [config]="configRect"></ko-rect> </ko-layer> </ko-stage> `, imports: [StageComponent, CoreShapeComponent], }) export default class App implements AfterViewInit { @ViewChild('rect') rect!: any; public configStage: StageConfig = { width: window.innerWidth, height: window.innerHeight, }; public configRect: RectConfig = { x: 50, y: 50, width: 100, height: 100, fill: 'red', shadowBlur: 10, shadowColor: 'black', shadowOffsetX: 5, shadowOffsetY: 5 }; ngAfterViewInit() { if (this.rect) { this.rect.getNode().cache(); } } }