3***@qq.com
3***@qq.com
  • 发布:2022-08-11 14:01
  • 更新:2022-08-11 15:06
  • 阅读:1037

vue3.0 nvue页面使用canvas报错

分类:HBuilder

vue3.0 nvue页面使用canvas报错

2022-08-11 14:01 负责人:无 分享
已邀请:
3***@qq.com
CODE_XU

CODE_XU

onLoad 中的代码在 onReady 中执行就可以了

  • 3***@qq.com (作者)

    放在onReady中还是报错

    14:55:17.394 [Vue warn]: Failed to resolve component: gcanvas

    14:55:17.413 If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

    14:55:17.432 at <IndexpageId=1pagePath="pages/index/index"__pageQuery={}>

    14:55:17.454 reportJSException >>>> exception function:gcanvas setBackGround for android view, exception:WX_RENDER_ERR_TEXTURE_SETBACKGROUND: TextureView doesn't support displaying a background drawable!

    2022-08-11 14:56

CODE_XU

CODE_XU

我精简了你的代码,可以正常运行

<template>  
    <view class="content">  
        <gcanvas  
            class="canvas"  
            :style="{ width: `${width}px`, height: '40px' }"  
            canvas-id="Canvas"  
            ref="Canvas"  
            id="Canvas"  
            @touchstart="touchstart"  
            @touchmove="touchmove"  
            @touchend="touchend"  
            fillStyle="#EEEEEE"  
        ></gcanvas>  
    </view>  
</template>  

<script>  
import { enable, WeexBridge } from '../../gcanvas/index.js';  
var modal = weex.requireModule('modal');  
export default {  
    data() {  
        return {  
            title: 'Hello',  
            subNVue: '',  
            isCanvas: false,  
            width: 360  
        };  
    },  
    onReady() {  
        let { windowWidth } = uni.getSystemInfoSync();  
        this.width = windowWidth;  
        var ganvas = this.$refs['Canvas'];  
        this.canvasObj = enable(ganvas, {  
            bridge: WeexBridge  
        });  
        this.context = this.canvasObj.getContext('2d');  
        var ctx = this.context;  
        setTimeout(() => {  
            ctx.lineWidth = 5;  
            ctx.beginPath();  
            ctx.moveTo(0, 0);  
            ctx.bezierCurveTo(0, 40, this.width, 40, this.width, 0);  
            ctx.setStrokeStyle('#6AA0FF');  
            // ctx.fillStyle('#6AA0FF');  
            ctx.setFillStyle('#6AA0FF');  
            ctx.stroke();  
            ctx.fill();  
            ctx.closePath();  
            ctx.draw(true);  
        }, 500);  
    }  
};  
</script>  

  • 3***@qq.com (作者)

    iOS没有问题,Android会报错

    2022-08-11 15:22

  • 3***@qq.com (作者)

    15:42:05.873 If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

    15:42:05.897 at <IdentityInfopageId=4pagePath="pagesB/identityInfo/identityInfo"__pageQuery={}>

    15:42:05.911 reportJSException >>>> exception function:gcanvas setBackGround for android view, exception:WX_RENDER_ERR_TEXTURE_SETBACKGROUND: TextureView doesn't support displaying a background drawable!

    2022-08-11 15:42

  • CODE_XU

    回复 3***@qq.com: 这个警告目前可以这样处理:

    打开 /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-shared/dist/uni-shared.cjs.js 文件,在 NVUE_BUILT_IN_TAGS 中添加 'gcanvas', 我们会在下一次发版时解决这个问题

    2022-08-11 15:58

  • 3***@qq.com (作者)

    回复 CODE_XU: 好的

    2022-08-11 16:16

  • 3***@qq.com (作者)

    回复 CODE_XU: 感谢

    2022-08-11 16:17

  • 3***@qq.com (作者)

    没有警告了, reportJSException >>>> exception function:gcanvas setBackGround for android view, exception:WX_RENDER_ERR_TEXTURE_SETBACKGROUND: TextureView doesn't support displaying a background drawable!这个错误还有

    2022-08-11 16:20

该问题目前已经被锁定, 无法添加新回复