当前位置:网站首页>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)
}
})
}
边栏推荐
- Leetcode 450.删除二叉搜索树中的结点
- [tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction
- Three simple tips for accelerating yarn install
- The meaning of FPGA abbreviations and words in engineering field
- 一文看懂经典BUCK-BOOST负电压电路
- 股票开账户如何优惠开户?在线开户安全么?
- MySQL中json_extract函数说明
- [tcapulusdb knowledge base] Introduction to tmonitor system upgrade
- Memory consistency and cache consistency
- 【OpenHarmony】usb gadget 配置hdc功能cfg文件解读
猜你喜欢

《ThreadLocal》
![[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)](/img/6d/8b1ac734cd95fb29e576aa3eee1b33.png)
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)

阻塞、非阻塞、多路复用、同步、异步、BIO、NIO、AIO 一文搞定

SaaS cloud tool, a sharp tool for change under the industrial Internet
![[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)](/img/d7/3a514fb75b3df487914a8db245ab89.png)
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)
![[tcapulusdb knowledge base] Introduction to new models of tcapulusdb](/img/2a/1d7f12c99b92d143e142ade8bc90f9.png)
[tcapulusdb knowledge base] Introduction to new models of tcapulusdb

get_edges

任何代码未动的情况下第二天项目访问速度明显下降,案例分析

Thread pool

Sleuth + Zipkin
随机推荐
OpenResty 基础
stylegan3:alias-free generative adversarial networks
Large area and availability area
万字攻略,详解腾讯面试(T1-T9)核心技术点,面试题整理
stylegan2:analyzing and improving the image quality of stylegan
uniapp对接腾讯即时通讯TIM 发图片消息问题
Web articles_ 01 understanding web development
批量注册组件
Summarize the experience of purchasing Alibaba cloud servers
Android kotlin collaboration Async
Charge pump principle handout, how is the voltage "pumped"?
Stone from another mountain - Intelligent Question and answer technology in wechat search
139. 单词拆分
Object
股票开户如何便宜一些?现在网上开户安全么?
子级文件拖到上一级
How NPM contracts and deletes packages
CAS操作在ARM和x86下的不同实现
window远程桌面连接互传文件加速小技巧
stylegan1: a style-based henerator architecture for gemerative adversarial networks