当前位置:网站首页>Custom components, using NPM packages, global data sharing, subcontracting
Custom components, using NPM packages, global data sharing, subcontracting
2022-07-03 01:44:00 【Blizzard front end】
Custom components
Component creation and reference
1. Create components
① In the root directory of the project , Right mouse button , establish components->test Folder
② In the new components->test folder , Right mouse button , Click on “ newly build Component”
③ Type the name of the component and press enter , Four files corresponding to the component will be automatically generated , The suffixes are .js,.json,.wxml and .wxss
2. Partial quote
The reference methods of components are divided into “ Partial quote ” and “ Global references ”, seeing the name of a thing one thinks of its function :
① Partial quote : Components can only be used within the currently referenced page
② Global references : Components can be used in every applet page
3. Local reference component
4. Global reference component
5. Global references VS Partial quote
According to the frequency and range of components , To choose the appropriate reference method :
① If a component Often used in multiple pages , Recommended “ Global references ”
② If a component Only used in specific pages , Recommended “ Partial quote ”
6. Differences between components and pages
Custom components - style
1. Component style isolation
2. Notes on component style isolation
3. Modify style isolation options for components
4.stylelsolation Optional values for
Custom components - data 、 Methods and properties
1.data data
2.methods Method
wx.showToast() Popup , Be similar to alert()
3.properties attribute
4.data and properties The difference between
5. Use setData modify properties Value
Custom components - Data listener
1. What is a data listener
2. Basic usage of data listener
3. Listen for changes in object properties
Custom components - Pure data fields
1. What is a pure data field
2. Usage rule
Quickly modify the same code Select the variable ,crtl+D
Custom components - Life cycle of components
1. All lifecycle functions of components
2. The main life cycle functions of components
3.lifetimes node
Custom components - The life cycle of the page on which the component resides
1. What is the declaration cycle of the page where the component is located
2.pageLifetimes node
3. Randomly initialize the component to show the content
Call when the page where the component is located is displayed
Custom components - slot
1. What is a slot
2. Single slot
3. Enable multiple slots
4. Define multiple slots
Custom components - Communication between parent and child components
1. Communication between parent and child components 3 Ways of planting
2. Attribute binding
3. Event binding
Personal leave binding steps
4. Get component instance
Custom components -behaviors
1. What is? behaviors
2.behaviors How it works
Every behavior Can contain a set of attribute 、 data 、 Life cycle functions and methods . When the component references him , Its properties 、 Data and methods Will be incorporated into the component
Each component can reference more than one behavior,behavior You can also quote other behavior.
3. establish behavior
4. Import and use behavior
5.behavior All available nodes in
6. Overwrite and combination rules of fields with the same name
Use npm package
The app is right npm Support and limitations of
Use npm package -Vant Weapp
1. What is? Vant Weapp
Vant Weapp It is a set of small programs that are open-source by the front-end team UI Component library , Help developers quickly build small application . What it uses is MIT Open source license agreement , For business
Friendly to use
2. install Vant Component library
In the applet project , install Vant The component library is mainly divided into the following three steps :
① adopt npm install
② structure npm package
③ modify app.son
First check whether there is package.json Package management profile ,
Configuration command
npm inint -y
3. Use vant Components
4. Customize the global theme style
CSS Custom variables also work on , overall situation html{ Definition CSS Custom variable }, The root node of wechat applet is page,page{// Set up CSS Custom variable }
5. Customize the global theme style
Use npm package -API Promise turn
1. Asynchronous based on callback function API The shortcomings of
shortcoming : Easy to cause the problem of callback hell , Code readability 、 Poor maintenance
2. What is? API Promise turn
3. Realization API Promise turn
npm i --save miniprogram-api-promise
Applets cannot be used directly node_modulese The bag inside , By building npm Will generate miniprogram_npm To use the bag just finished , It is recommended to delete before each build miniprogram_npm Folder to avoid reporting errors
4. call Promise Asynchrony after API
Global data sharing
1. What is data sharing
2. Global data sharing scheme in applet
Global data sharing -MobX
1. install MobX Related to the package
2. establish MobX Of Store example
3. take Store The members inside are bound to the page
4. Use on the page Store Members of the
5. take Store Bind members in to components
6. Use in components Store Members of the
to subcontract
1. What is subcontracting
Subcontracting refers to putting a complete applet project , It is divided into different sub packages according to requirements , Package into different sub packages at build time , When users use it Load on demand
2. Benefits of subcontracting
The benefits of subcontracting small programs mainly include the following two points :
① Can optimize the download time of the first start of the applet
② It can better decouple and cooperate when multiple teams develop together
3. Composition of the project before subcontracting
4. Composition of the project after subcontracting
5. Subcontracting loading rules
6. Volume limit of subcontracting
to subcontract - Use subcontracting
1. Configuration method
2. Packaging principles
3. Citation principle
to subcontract - Independent subcontracting
1. What is independent subcontracting
2. The difference between independent subcontracting and ordinary subcontracting
3. Application scenarios of independent subcontracting
4. Configuration method of independent subcontracting
5. Citation principle
to subcontract - Subcontracting pre download
1. What is subcontracting pre download
Subcontracting pre download refers to : When entering a page of the applet , The framework automatically pre downloads the subcontracts that may be required , So as to improve the startup speed when entering the subsequent subcontracting page
2. Configure the pre download of subcontracting
3. Restrictions on subcontracting pre download
边栏推荐
- How is the mask effect achieved in the LPL ban/pick selection stage?
- [AUTOSAR cantp] -2.11-uds diagnostic response frame data segment data padding data filling and data optimization data optimization (Theory + configuration)
- [error record] navigator operation requested with a context that does not include a naviga
- C application interface development foundation - form control (3) - file control
- Network security - the simplest virus
- 【数据挖掘】任务4:20Newsgroups聚类
- 【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
- Network security - talking about security threats
- Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
- Vant 实现简单的登录注册模块以及个人用户中心
猜你喜欢
High resolution network (Part 1): Principle Analysis
wirehark数据分析与取证A.pacapng
CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)
C#应用程序界面开发基础——窗体控制(3)——文件类控件
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
Niuniu's ball guessing game (dynamic planning + prefix influence)
[技术发展-23]:DSP在未来融合网络中的应用
[data mining] task 6: DBSCAN clustering
随机推荐
View of MySQL
Network security - firewall
What is tone. Diao's story
How is the mask effect achieved in the LPL ban/pick selection stage?
[AUTOSAR cantp] -2.11-uds diagnostic response frame data segment data padding data filling and data optimization data optimization (Theory + configuration)
PS去除水印详解
Network security - virus
Virtual list
String splicing function of MySQL
网络安全-信息收集
[shutter] animation animation (animatedwidget animation use process | create animation controller | create animation | create animatedwidget animation component | animation operation)
Installation and use of serial port packet capturing / cutting tool
网络安全-动态路由协议RIP
Openresty cache
Function definition and call, this, strict mode, higher-order function, closure, recursion
Common English Vocabulary
网络安全-破解系统密码
Network security - cracking system passwords
网络安全-木马
Network security - vulnerabilities and Trojans