Introduction to Global Data, function reuse, templates, and other examples of WeChat applets

Source: Internet
Author: User
This article mainly introduces the detailed introduction of global data, function reuse, and templates for small programs, for more information about how to define global data, function reuse, templates, and other examples of small programs, see the next article.

Summary:

1. how to define global data

In the app. data or functions defined in js App ({}) are global. you can use var app = getApp (); app on the page. function/key method, but we do not need to apply it again. defines global functions in js.

2. how to reuse code

Function reuse:

test.jstest: function(){}module.exports={ test:test }other.jsvar common = require('test.js');page({  common.test()})

Template:

  
  
   
Odd
  
 
  
  
   
Even
  
 
   
  
 // Templates can be defined in other files on our page
 But the import has the concept of scope, that is, only the template defined in the target file will be imported, and the template/include of the import target file will not be imported.
 The entire code is introduced, which is equivalent to copying to the include position.

3. for attributes whose values are boolean type, such as the active attribute of the SS component and the checked attribute of the checkbox. Whether set to true or false, this attribute takes effect. this is also the case in html, but it can be rendered successfully by using checked =.

Thank you for reading this article. I hope it will help you. thank you for your support for this site!

The above is the details about the definition of global data, function reuse, templates, and other instances for small programs. For more information, see other related articles in the first PHP community!

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.