5***@qq.com
5***@qq.com
  • 发布:2021-03-04 15:51
  • 更新:2021-11-13 23:56
  • 阅读:2626

支持canvas 2d的怎么改啊

分类:uni-app

canvas 2d 接口支持同层渲染且性能更佳,建议切换使用。详见文档:https://developers.weixin.qq.com/miniprogram/dev/component/canvas.html#Canvas-2D-%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81

2021-03-04 15:51 负责人:无 分享
已邀请:
c***@foxmail.com

c***@foxmail.com

注意canvas-id和id都需要填写。

<template>  
    <view class="container">  
        <canvas type="2d" style="width: 300px; height: 200px;" id="firstCanvas" canvas-id="firstCanvas" @error="canvasIdErrorCallback"></canvas>  
    </view>  
</template>  

<script>  
import store from '@/store';  

export default {  
    name: "board",  

    computed: {  
        phoneInch() {  
            // fetch it from localStorage, but not network.  
            return store.state.global.phoneInch;  
        },  
    },  

    onLoad() {  
        console.debug("board load");  
    },  

    onReady: function (e) {  
        const query = wx.createSelectorQuery()  
        query.select('#firstCanvas')  
            .fields({ node: true, size: true })  
            .exec((res) => {  
                const canvas = res[0].node  
                const ctx = canvas.getContext('2d')  

                const dpr = wx.getSystemInfoSync().pixelRatio  
                canvas.width = res[0].width * dpr  
                canvas.height = res[0].height * dpr  
                ctx.scale(dpr, dpr)  

                ctx.fillRect(0, 0, 100, 100)  
            });  
    },  
    methods: {  
        canvasIdErrorCallback: function (e) {  
            console.error(e.detail.errMsg)  
        }  
    }  
}  
</script>  

<style scoped>  
.container{  
    width: 100%;  
    height: 100%;  
}  
</style>
  • 飞飞吕

    用不了呀 报错 打印res 为 [unll]

    2022-09-01 18:07

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