Similar to pages, custom components have their own
wxml templates and
Componentization, in turn, understand, write repeated pages and methods, and it will be annoying to write the second time. Extracting out is componentization, which can be understood as a common method
For general data, the first thing you think of or should contact is template, but template has a shortcoming, that is, it is only page effect, and there will be no corresponding js operation.
Of course, this is just the most basic thinking. Since it is a component, it is a one-to-many relationship for pages. Multiple pages are woven into components, how do they link up? The pages page can pass values to the component component, and the natural component will also correspond to the callback method customized by pages. As long as you can think of and want to achieve, there will be corresponding offers.
Implementation method, create a new component in the directory, it will automatically generate the corresponding js, json, wxml, wxss, basically similar to pages
Take a look at the contents of each component file
options, multipleslots:true Enable multiple slot support in the build.
properties, which can define some properties of receiving pages.
data, the data of the component
method, the method of component extraction
1. you need to configure the components in the json of the pages page
Talk about options
You can in the wxml of the component
Specify the corresponding pages page content through the name attribute of the slot
Talk about properties
Pass a num attribute in the custom label
In the component can be passed through properties
Get the num value can be obtained through this.properties.num
Data usage is the same as page.
The most important thing is the method event
Relative to components, page is a one-to-many process
Since it is extracted, the components can only do some common things, and some private implementations must be introspected through the page.
This involves callbacks. For example, add a bindtap method to the component.
But the customevent method of this component page is bound.
In methods, call the method implemented by page itself through treggerEvent.
ok, this is an introduction to componentization
My blog is about to be moved and synchronized to Tencent Cloud + community, and everyone is invited to join: https://cloud.tencent.com/developer/support-plan?invite_code=3k8xfjgejtk4w