当前位置:网站首页>Batch registration component
Batch registration component
2022-06-23 16:08:00 【@Sea life】
General steps :
1 Use require Provided function context Load all... In a directory .vue Postfix file .
2 then context Function will return an import function importFn
3 It has another attribute keys() Get all file paths
4 Through the file path array , By traversing the array , Reuse importFn Import component objects according to the path
5 You can register globally while traversing
// In fact, that is vue plug-in unit , Expand vue function , Global components 、 Instructions 、 function (vue.30 Cancel filter )
// When you are in mian.js Import , Use Vue.use() (vue3.0 app) When it's done install function
// import XtxSkeleton from './xtx-skeleton.vue'
// import XtxCarousel from './xtx-carousel.vue'
// import XtxMore from './xtx-more.vue'
// import XtxBread from './xtx-bread.vue'
// import XtxBreadItem from './xtx-bread-item.vue'
// Import library All components under the folder
// Batch import requires a function require.context(dir,deep,matching)
// Parameters :1. Catalog 2. Whether to load subdirectories 3. Loaded regular matches
const importFn = require.context('./', false, /\.vue$/)
// console.dir(importFn.keys()) File name array
export default {
install (app) {
// app.component(XtxSkeleton.name, XtxSkeleton)
// app.component(XtxCarousel.name, XtxCarousel)
// app.component(XtxMore.name, XtxMore)
// app.component(XtxBread.name, XtxBread)
// app.component(XtxBreadItem.name, XtxBreadItem)
// Batch register global components
importFn.keys().forEach(key => {
// Import components
const component = importFn(key).default
// Certified components
app.component(component.name, component)
})
// Defined instruction
defineDirective(app)
}
}
const defineDirective = (app) => {
// Image lazy loading instruction v-lazyload
app.directive('lazyload', {
// vue2.0 inserted function , After element rendering
// vue3.0 mounted function , After element rendering
mounted (el, binding) {
// Element can only be obtained after it is inserted dom Elements , Can be used intersectionobserve Monitor and enter the visual area
// el It's a picture element binding.value Picture address
const observe = new IntersectionObserver(([{
isIntersecting }]) => {
if (isIntersecting) {
el.src = binding.value
// Cancel observation
observe.unobserve(el)
}
}, {
threshold: 0.01
})
// To observe
observe.observe(el)
}
})
}
边栏推荐
- Variable declaration of go language
- npm 如何发包 删包
- 提高效率 Or 增加成本,开发人员应如何理解结对编程?
- Understand the classic buck-boost negative voltage circuit
- [tcapulusdb knowledge base] Introduction to new models of tcapulusdb
- 《ThreadLocal》
- 服务器的部署及使用说明
- 要买的理财产品年限长,划算吗?
- Apache commons tool class
- Matlab| sparse auxiliary signal denoising and pattern recognition in time series data
猜你喜欢

总结一下购买阿里云服务器的经验
![生成二叉搜索平衡树[利用树递归特性]](/img/b3/f8edf45bdfdced7c3698088dbf7d84.png)
生成二叉搜索平衡树[利用树递归特性]

Big factory Architect: how to draw a grand business map?

进阶开发- 泛型入门基础类测试

Sleuth + Zipkin

SQL窗口函数怎么使用

SaaS cloud tool, a sharp tool for change under the industrial Internet

MySQL transactions and locks

Tips for accelerating file transfer between windows remote desktop connections

Redis集群操作的方法
随机推荐
Block, non block, multiplexing, synchronous, asynchronous, bio, NiO, AIO
stylegan1: a style-based henerator architecture for gemerative adversarial networks
Web篇_01 了解web开发
C. Add One--Divide by Zero 2021 and Codeforces Round #714 (Div. 2)
电荷泵原理讲义,电压是怎么“泵”上去的?
Web容器是怎样给第三方插件做初始化工作的
Leetcode 450.删除二叉搜索树中的结点
pytorch:模型的保存与导出
matlab: 如何从一些数据里知道是由哪些数据相加得出一个已知数
子级文件拖到上一级
Avoid these six difficulties and successfully implement MES system
A tour of gRPC:01 - 基础理论
stylegan2:analyzing and improving the image quality of stylegan
【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)
Advanced development - generic entry basic class test
一文看懂经典BUCK-BOOST负电压电路
OpenResty 基础
Detailed explanation of MQ message oriented middleware theory
阻塞、非阻塞、多路复用、同步、异步、BIO、NIO、AIO 一文搞定
Build vscode into an invincible IDE (14) tasks JSON and launch JSON configuration details, add automation tasks at will