Vue [nine] vue import and export syntax

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

  1. Default export:
  • export by defaultexport defaut
  • There can only be one default export in a file, for example:export default router
  1. 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

  1. 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
  1. 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 neededimport { 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

Guess you like

Origin blog.csdn.net/qq_51602285/article/details/128179442