Import tag là gì
WordPress | Hoi dap WordPress | Hỏi đáp WordPress | WordPress FAQ | Hoc WordPress | Su dung WordPress | Lap trinh WordPress | Plugin WordPress | SEO WordPress | Thuat ngu WordPress | Huong dan su dung WordPress
The Syntax
ValueThe url The full URL to the module, includes query parameters and/or hash (following the 0 or 1). In browsers, this is either the URL from which the script was obtained (for external scripts), or the URL of the containing document (for inline scripts). In Node.js, this is the file path (including the 2 protocol).DescriptionThe 4, a dot, and the identifier 5. Because 4 is a reserved word, not an identifier, this is not a property accessor, but a special expression syntax.The 9 within a module) is a syntax error.ExamplesPassing query parametersUsing query parameters in the 4 specifier allows module-specific argument passing, which may be complementary to reading parameters from the application-wide 1 (or on Node.js, through 2). For example, with the following HTML:
The 3 module is able to retrieve the 4 parameter through import.meta :
The same applies when a module imports another:
The ES module implementation in Node.js supports resolving module specifiers containing query parameters (or the hash), as in the latter example. However, you cannot use queries or hashes when the module is specified through the CLI command (like 6), because the CLI entrypoint uses a more CommonJS-like resolution mode, treating the path as a file path rather than a URL. To pass parameters to the entrypoint module, use CLI arguments and read them through 2 instead (like 8).Getting current module's file pathIn Node.js CommonJS modules, there's a 9 variable that contains the absolute path to the folder containing current module, which is useful for resolving relative paths. However, ES modules cannot have contextual variables except for import.meta . Therefore, to get the current module's file path, you can use 1. |