in the vue official document about "automatic global registration of basic components", there is a code:
import Vue from "vue"
import upperFirst from" lodash/upperFirst"
import camelCase from "lodash/camelCase"
const requireComponent = require.context (
/ / the relative path of its component directory
". / components",
/ / whether to query its subdirectory
false,
/ / matches the regular expression
/ Base [Amurz] wband. (vue | js) $/
)
requireComponent.keys () .forEach (fileName = > {
/ / get component configuration
const componentConfig = requireComponent (fileName)
/ / get the PascalCase name of the component
const componentName = upperFirst (
camelCase(
// `./`
fileName.replace(/^\.\/(.*)\.\w+$/, "$1")
)
)
/ / globally register components
Vue.component (
componentName,
// `export default`
// `.default`
//
componentConfig.default || componentConfig
)
})
I"d like to ask about the last line of code when I use componentConfig instead of componentConfig.default. I tried to remove the export default and found that the console printed {default: {.},.}
.