当前位置:网站首页>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
边栏推荐
- 缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
- 微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
- CFdiv2-Fixed Point Guessing-(區間答案二分)
- Coroutinecontext in kotlin
- Internal connection query and external connection
- [shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
- Asian Games countdown! AI target detection helps host the Asian Games!
- Kotlin middle process understanding and Practice (II)
- Query product cases - page rendering data
- Detailed introduction to the deployment and usage of the Nacos registry
猜你喜欢

深度学习笔记(持续更新中。。。)

How do it students find short-term internships? Which is better, short-term internship or long-term internship?

stm32F407-------IIC通讯协议

MySQL learning 03

Visualisation de l'ensemble de données au format yolov5 (fichier labelme json)

Solution for processing overtime orders (Overtime unpaid)

Ni visa fails after LabVIEW installs the third-party visa software

stm32F407-------ADC

Deep learning notes (constantly updating...)

【Camera专题】Camera dtsi 完全解析
随机推荐
苏世民:25条工作和生活原则
Huakaiyun | virtual host: IP, subnet mask, gateway, default gateway
Everything file search tool
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
Huakaiyun (Zhiyin) | virtual host: what is a virtual host
DML Foundation
stm32F407-------ADC
创建+注册 子应用_定义路由,全局路由与子路由
[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)
Hard core observation 547 large neural network may be beginning to become aware?
Button button adaptive size of wechat applet
Technology sharing | Frida's powerful ability to realize hook functions
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
Exception handling in kotlin process
The technology boss is ready, and the topic of position C is up to you
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
【Camera专题】OTP数据如何保存在自定义节点中
Custom components, using NPM packages, global data sharing, subcontracting
详细些介绍如何通过MQTT协议和华为云物联网进行通信
Machine learning notes (constantly updating...)