用于 javascript 的 VSCode 智能感知不适用于 Canvas 元素

问题描述 投票:0回答:2

VScode 智能感知在 HTML 5“canvas”元素上工作是否存在问题? Intellisense 不提供自动完成支持

var canvas = document.getElementById("canvas")
canvas.getC... /*there is no .getContext("2d")*/

javascript canvas
2个回答
9
投票

使用 JSDoc

@type
获取
canvas
元素:

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

查看更多:在 VS Code 中获取 HTML Canvas 的 IntelliSense 作者:Nathan Vaughn


0
投票

你也可以这样做。从 HTML 中删除画布,并使用 javascript 代码动态添加它。

let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
document.body.appendChild(canvas);
© www.soinside.com 2019 - 2024. All rights reserved.