当前位置:网站首页>require. context
require. context
2022-07-03 02:10:00 【[email protected]】
adopt require.context() Function to create your own context. It takes three parameters :
const requireComponent = require.context(
// The relative path of its component Directory , File path
'./components',
// Whether to query its subdirectories
false,
// Regular expressions that match the file name of the underlying component , Match some files
/Base[A-Z]\w+\.(vue|js)$/
)
The export methods are 3 Attributes : resolve, keys, id
resolve It's a function , It returns the module after the request is parsed id.
keys It's also a function , It returns an array , It consists of all requests that may be processed by the context module .
id Is the module contained in the context module id. It may be used by you module.hot.accept When it comes to
Through it, we can export some resources in batches, such as pictures , Components , Object etc. . such as Vue Cases of officially provided registered components :
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 subdirectories
false,
// Regular expressions that match the file name of the underlying component
/Base[A-Z]\w+\.(vue|js)$/
)
requireComponent.keys().forEach(fileName => {
// Get component configuration
const componentConfig = requireComponent(fileName)
// Get the PascalCase name
const componentName = upperFirst(
camelCase(
// Get the file name independent of the directory depth
fileName
.split('/')
.pop()
.replace(/\.\w+$/, '')
)
)
// Global registration component
Vue.component(
componentName,
// If this component option is through `export default` Derived ,
// Then priority will be given to `.default`,
// Otherwise, go back to the root of the module .
componentConfig.default || componentConfig
)
})
notes : The understanding here is not deep enough , It's just that when you see someone else write this in the project, record it first , Wait until you come back later .
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/184/202207030156275358.html
边栏推荐
- In the face of difficult SQL requirements, HQL is not afraid
- 小程序开发黑马购物商城中遇到的问题
- Detailed introduction to the deployment and usage of the Nacos registry
- LabVIEW安装第三方VISA软件后NI VISA失效
- 苏世民:25条工作和生活原则
- Kotlin middle process understanding and Practice (II)
- File class (add / delete)
- Asian Games countdown! AI target detection helps host the Asian Games!
- 2022 spring "golden three silver four" job hopping prerequisites: Software Test interview questions (with answers)
- How do it students find short-term internships? Which is better, short-term internship or long-term internship?
猜你喜欢
Processing of tree structure data
Anna: Beibei, can you draw?
stm32F407-------DMA
Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
[shutter] top navigation bar implementation (scaffold | defaulttabcontroller | tabbar | tab | tabbarview)
In the face of difficult SQL requirements, HQL is not afraid
LabVIEW安装第三方VISA软件后NI VISA失效
The testing process that software testers should know
His experience in choosing a startup company or a big Internet company may give you some inspiration
MySQL学习03
随机推荐
Caused by: com. fasterxml. jackson. databind. exc.MismatchedInputException: Cannot construct instance o
es6 filter() 数组过滤方法总结
502 (bad gateway) causes and Solutions
How can retail enterprises open the second growth curve under the full link digital transformation
树形结构数据的处理
What are the key points often asked in the redis interview
苏世民:25条工作和生活原则
SPI机制
Summary of ES6 filter() array filtering methods
easyExcel
小程序开发黑马购物商城中遇到的问题
返回一个树形结构数据
Leetcode(540)——有序数组中的单一元素
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
Use go language to realize try{}catch{}finally
我的创作纪念日
Network security OpenVAS
Asian Games countdown! AI target detection helps host the Asian Games!
Anna: Beibei, can you draw?
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China