canvas 在vscode没有代码提示问题(vue|html)

1,318 阅读1分钟

解决方案

在对应的属性(变量)上面添加type,给vscode提供类型支持,如下图所示:

image.png

/** @type {HTMLCanvasElement} */
/** @type {CanvasRenderingContext2D} */

如果是在HTML中,注释加在变量的上面

 /** @type {HTMLCanvasElement} */
 const canvas = document.getElementById('canvas')

thinking more... 使用这种方式我们可以给更多的变量或者属性添加代码提示,例如video元素

image.png