jQuery intellisense in VS Code

前端 未结 5 1512
半阙折子戏
半阙折子戏 2021-01-31 18:05

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 C

相关标签:
5条回答
  • 2021-01-31 18:34

    Type this command in your project root :

    npm i --save @types/jquery
    
    0 讨论(0)
  • 2021-01-31 18:35

    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

    0 讨论(0)
  • 2021-01-31 18:37

    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"
            ]
        }
    
    }
    
    0 讨论(0)
  • 2021-01-31 18:39

    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.)

    0 讨论(0)
  • 2021-01-31 18:40

    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.

    0 讨论(0)
提交回复
热议问题