Skip to main content
Version: 3.x

Taro.createCanvasContext(canvasId, component)

Creates a CanvasContext object.

Tip: The canvasId needs to be specified, the drawing context only works on the corresponding <canvas/>; in addition, you need to execute it in the useReady callback in the web side, otherwise it will get the CanvasContext before the underlying canvas is rendered, resulting in the underlying context being undefined and thus can't draw properly.

Reference

Type

(canvasId: string, component?: Record<string, any>) => CanvasContext

Parameters

PropertyTypeDescription
canvasIdstringThe canvas-id property of the canvas component whose context needs to be obtained.
componentRecord<string, any>In a custom component, the "this" of the current component instance means to search for the canvas with the canvas-id in this custom component. If this parameter is not specified, no search is performed in any custom component.

API Support

APIWeChat Mini-ProgramH5React Native
Taro.createCanvasContext✔️✔️