Home > Web Front-end > JS Tutorial > How to Import jQuery in ES6 Syntax?

How to Import jQuery in ES6 Syntax?

Susan Sarandon
Release: 2024-10-25 02:55:02
Original
236 people have browsed it

How to Import jQuery in ES6 Syntax?

Importing jQuery in ES6 Syntax

Problem

Migrating to ES6 syntax for an app using a library built on jQuery can lead to questions about importing jQuery in the new syntax.

Solution

1. Import from the node_modules Directory

import * as stylesheet from '../assets/styles/app.scss';<br>import {$, jQuery} from 'jquery'; // Import from node_modules<br>import * as jquery3 from '../dist/scripts/jquery.min';</p>
<p>console.log($('my-app'));<br>

2. Export for Other Scripts

window.$ = $;<br>window.jQuery = jQuery;<br>

Notes

  • Using the glob as is unnecessary because specific objects are being imported.
  • It's beneficial to import both $ and jQuery to cover all usage scenarios.
  • Exposing the import to other scripts using window.$ = $ is essential.

The above is the detailed content of How to Import jQuery in ES6 Syntax?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template