#2070·F2

如何在Uniapp 的App端使用AntV F2

Author: willcongCreated Jun 23, 2025Updated Jun 24, 2025

因为直接用f-vue,在app端遇到canvas的context报错问题。我目前对照f-vue项目中的index.ts文件,做了一个适配,但还是报错。该从哪里下手。 //#ifdef APP-PLUS context = uni.createCanvasContext('f2-canvas-app', this); returnObject = { ...props, children: toRawChildren($slots), }; //#endif // #ifndef APP-PLUS context = canvasEl.getContext('2d'); returnObject = { ...props, // context 内部创建,不能被覆盖 context, children: toRawChildren($slots), };

错误信息: 14:29:04.655 TypeError: Cannot read property 'createElement' of undefined 14:29:04.655 [JS Framework] Failed to execute the callback function: TypeError: Cannot read property 'createElement' of undefined 14:29:04.686 reportJSException >>>> exception function:WEEX_CALL_JAVASCRIPT, exception:JavaScript execute error!Uncaught TypeError: Cannot read property 'createElement' of undefined at OffscreenCanvasCreator2.getOrCreateCanvas (app-service.js:126215:36) at TextService2.measureFont (app-service.js:127302:58) at TextService2.measureText (app-service.js:127364:35) at TextUpdater2.update (app-service.js:125034:54) at DefaultStyleValueRegistry2.updateGeometry (app-service.js:123935:37) at DefaultStyleValueRegistry2.processProperties (app-service.js:123790:16) at DefaultStyleValueRegistry2.recalc (app-service.js:123919:16) at RenderingService2.renderDisplayObject (app-service.js:126368:49) at (app-service.js:126393:17) at RenderingService2.renderDisplayObject (app-service.js:126392:55)