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.
Type
(canvasId: string, component?: Record<string, any>) => CanvasContext
Parameters
Property | Type | Description |
---|---|---|
canvasId | string | The canvas-id property of the canvas component whose context needs to be obtained. |
component | Record<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
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.createCanvasContext | ✔️ | ✔️ |