当前位置:网站首页>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
边栏推荐
- How do browsers render pages?
- 苏世民:25条工作和生活原则
- 2022 spring "golden three silver four" job hopping prerequisites: Software Test interview questions (with answers)
- [shutter] top navigation bar implementation (scaffold | defaulttabcontroller | tabbar | tab | tabbarview)
- Analyzing several common string library functions in C language
- Summary of ES6 filter() array filtering methods
- 浏览器是如何对页面进行渲染的呢?
- Leetcode 183 Customers who never order (2022.07.02)
- His experience in choosing a startup company or a big Internet company may give you some inspiration
- 转载收录6.5大侠写的部分Qt开发经验
猜你喜欢

Redis:Redis的简单使用

Recommendation letter of "listing situation" -- courage is the most valuable

《上市风云》荐书——唯勇气最可贵

LabVIEW安装第三方VISA软件后NI VISA失效

机器学习笔记(持续更新中。。。)

Asian Games countdown! AI target detection helps host the Asian Games!

What are the key points often asked in the redis interview

微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题

MySQL学习03

MySQL learning 03
随机推荐
Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
String replace space
Reprint some Qt development experience written by great Xia 6.5
Comment le chef de file gère - t - il l'équipe en cas d'épidémie? Contributions communautaires
[camera topic] turn a drive to light up the camera
Prohibited package name
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
Swift开发学习
Caused by: com. fasterxml. jackson. databind. exc.MismatchedInputException: Cannot construct instance o
Redis: simple use of redis
[camera topic] how to save OTP data in user-defined nodes
Coroutinecontext in kotlin
The technology boss is ready, and the topic of position C is up to you
疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
Solution for processing overtime orders (Overtime unpaid)
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
[Flutter] dart: class;abstract class;factory;类、抽象类、工厂构造函数
How to refresh the opening amount of Oracle ERP