jQuery intellisense in VS Code

不想你离开。 提交于 2021-02-05 14:53:56

问题


I have tried this:

JQuery intellisense in Visual Studio Code

and this:

http://shrekshao.github.io/2016/06/20/vscode-01/

But it does nothing, VS Code just won't add jquery intellisense, I've been trying to solve this for hours but it just won't work


回答1:


Most of the blog postings are now outdated, as we finally have automatic type acquisition with version 1.8+ - you no longer need to install the typings yourself.

I recommend reading the official documentation, its always up to date: https://code.visualstudio.com/docs/languages/javascript

If you use npm and have a package.json in your project and jQuery is listed there, it should already work.

If you do not use npm, you can create the file jsconfig.json in the project root with the following content and you are good to go:

{
    "typeAcquisition": {
        "include": [
            "jquery"
        ]
    }

}



回答2:


Type this command in your project root :

npm i --save @types/jquery



回答3:


I had the same problem and google brought me here. I added the type jsconfig.json and "typeAcquisition" and still nothing.

Turns out you have to have node and npm installed. Even if you are not using them for package management and are importing jquery from a CDN.

From the Docs

Many popular libraries ship with typings files so you get IntelliSense for them automatically. For libraries that do not include typings, VS Code's Automatic Type Acquisition will automatically install community maintained typings file for

Automatic type acquisition requires npmjs, the Node.js package manager, which is included with the Node.js runtime. In this image you can see IntelliSense, including the method signature, parameter info, and the method's documentation for the popular lodash library.

https://code.visualstudio.com/docs/nodejs/working-with-javascript

So vs code uses npm for auto type acquisition.

May be super basic, but it solved my problem so I hope it helps someone else too.

I also used the configuration in jsconfig.json as described by kwood. Not sure I needed to specify it manually after installin npm but it is working so i'm not asking questions




回答4:


I thought that the major reason is Vscode does not parse the Jquery.js file because original jquery file is minified, which leads to vscode stop tokenization of the file. To solve this, open the jquery.js file, right click and select format. The tokenization process will complete.




回答5:


What helped me was using the non-minified version of jQuery, and then use

/// <reference path="./jquery-3.4.1.js" />

in the beginning of my JS file.

(I'm coding client-side i.e. ES5 JavaScript that is added to the page directly with the <script> tag.)



来源:https://stackoverflow.com/questions/41777327/jquery-intellisense-in-vs-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!