Vue [nine] vue import and export syntax
foreword
The import and export syntax in Vue is often seen and often used. The import and export syntax is mainly divided into default and on-demand.
1. Export by default
- Default export:
- export by default
export defaut
- There can only be one default export in a file, for example:
export default router
- Import by default:
- If the default export is used, the default import must be used
import router from "@/router"
[The object name after import can be taken at will]
2. Export on demand
- Export on demand:
- Export on demand
export
e.g.export const constantRoutes = ()=>{}
- Export can be a variable, array, object, function, etc.
- Export on demand can export multiple members
- Import on demand:
-
To import members exported on demand you must use import on demand
-
On-demand import syntax:
import { login } from "@/api/user"
(multiple members can be exported with,
separation) -
Import aliases as needed
import { login as loginUser } from "@/api/user"
-
Batch import directly when
import * as all from "@/api/user"
usingall.login()
Summarize:
-
The default export is usually used when only one member is exported in the file
-
On-demand export is usually used when only multiple members are to be exported in the file