How to encapsulate and make public components of WeChat applets

Source: Internet
Author: User
During the development process, we often encapsulate some common functional code or effects into components one by one, and then call them on the pages needed. For the development of small programs, we can also encapsulate some public components. During the development process, we often encapsulate some common functional code or effects into components one by one, and then call them on the pages needed.
For the development of small programs, we can also encapsulate some public components.

Next we will explain a menu that can be expanded by clicking the icon.

WXML (APP. wxml) of the page)

     
          
               
                    
                     
                 
                
                    
                         
       
       
        
        
       
         Homepage
        
                      
                     
                         
       
       
        
        
       
         Order
        
                      
                     
                         
       
       
        
        
       
         My
        
                      
                     
                         
                      
                 
             
       
      
          
       
  
 

This is mainly the display effect of the pressure surface of the plug-in, which can be written in the label.
Page JS (APP. js)

Var iconList ={}; // Set an object name to store data iconList. wdg = {// The page data to be stored for the VIEW layer. closeAllIcon and showAllIcon are the corresponding methods: data: {index: 0, close: 0}, closeAllIcon: function (e) {this. setData ({close: 1})}, showAllIcon: function (e) {this. setData ({close: 0}) }}; module. exports = iconList // expose the interface for convenient calling outside

The package is encapsulated, so how to use it.
On the required WXML page:
By introducing the catty page

 

.
On the required WXML page:

Use var iconList = require ('../wdg/iconlist') to introduce the corresponding JS

var util= require('../../util/util');var Page = new util.Page({    Wdgs: [iconList.Wdg]});

Introduce the corresponding file.

For more articles on how to encapsulate and create public components of applets, please follow the PHP Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.