wechat-miniprogram / lottie-miniprogram

lottie for miniprogram
MIT License
362 stars 40 forks source link

开发者工具报错小程序不支持动态创建组件, 线上安卓机会报WebGLCanvasContext2d的错 使用的是taro框架 #32

Closed gaoxing888 closed 1 year ago

lqliqi commented 1 year ago

请教一下这个怎么解决的 ?

vickyleu commented 1 year ago

请教一下这个怎么解决的 ?

其实是报错有问题,实际上可能是你的context为null

export interface CanvasNode {
    getContext(type: '2d'): CanvasRenderingContext2D;

    width: number;
    height: number;
    _left: number;
    _top: number;
    // ... 其他方法和属性
}

export function canvasNode(canvasTag: string): Promise<CanvasNode> {
    return new Promise((resolve, reject) => {
        Taro.createSelectorQuery().select(canvasTag).node((ref) => {
            if (ref) {
                const canvas = ((ref as unknown as unknown[]).length > 0) ? ref[0].node : ref.node;
                if (canvas) {
                    console.log(`typeof canvas==>${Object.getPrototypeOf(canvas)}`)
                    resolve(canvas);
                } else {
                    reject(ref);
                }
            }
        }).exec();
    })
}