在新的 VS Code 编辑器中,假设我有两个 javascript 文件 foo.js
和 bar.js
,其中 bar.js
包含这个:
module.exports.sayBar = function () {
console.log('bar')
}
在 foo.js
中,如果我输入 require('./bar').
并按 ctrl+space
激活智能感知,它没有检测到模块中的方法之一是 sayBar()
(我已经有默认的 jsconfig.json
文件,VS Code 会询问您是否要生成)。
是否有其他配置步骤来激活我编写的其他 JS 文件的智能感知?我真的很喜欢 VS Express 中 C++ 项目的这个功能,在我看来,它会让 VS Code 彻底击败 Atom。
最佳答案
它确实适用于 CommonJS 模块。在您的示例中,它应该是:
exports.sayBar = function() {
console.log('bar');
};
或
module.exports = {
sayBar: function() {
console.log('bar');
}
};
关于javascript - Visual Studio Code - 跨 JS 模块的智能感知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37604835/