WeChat Mini Programs custom components, canvas components have no effect

the custom component in WeChat Mini Programs, but the canvas component has no effect. Has anyone ever encountered this problem?

  ready(){
    const ctx = wx.createCanvasContext("back-canvas")
    ctx.setFillStyle("red")
    ctx.fillRect(10, 10, 150, 75)
    ctx.draw();
  },
<canvas class="ca" canvas-id="back-canvas" style="width:200px;height:200px;"></canvas>

createCanvasContext has two parameters. You need to pass this in a This, component in the page page by default.

const ctx = wx.createCanvasContext ('myCanvas',this);


just write it in the onLoad function or onShow function


the second parameter, just add this.
const ctx = wx.createCanvasContext ('back-canvas',this)


clipboard.png


the width and height of canvas does not need to be written in style. Try


I haven't found any reason either. In the form of page, you can


Note: ID selector, property selector, and signature selector should not be used in component wxss.
Is this the reason for

?


have you solved it?


what is the reason why canvas is not displayed on the real machine? Open debugging and see

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf66af-31353.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf66af-31353.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?