Home>Article>WeChat Applet> Sharing practical examples from getting started with WeChat mini programs (4)

Sharing practical examples from getting started with WeChat mini programs (4)

小云云
小云云 Original
2018-02-23 14:30:30 1777browse

Debugging method

Debugging of small programs is similar to general web debugging, but pay attention to a few points:

  • Selection of debugging files

Open the debugger, select theSourcestab, and then use the shortcut key:ctrl+pto open the search box and select the file with the suffixsmPerform debugging.
Sharing practical examples from getting started with WeChat mini programs (4)

  • Display of data binding

Open the debugger and selectAppDatatab, you can check the detailed information of page data binding and whether it is bound correctly. Records the data binding content of all pages.
Sharing practical examples from getting started with WeChat mini programs (4)
Through the above picture, we can know that only thedatesArryobject contains data that needs to be bound to the page.

TemplateTemplate

wxml / wxss / jsModule reuse, better encapsulation of UI and business logic to increase reusability

When an area needs to be used in multiple places, you can make this area into a template and call this template when using it. This will reduce the writing of repeated code, is easy to maintain, and makes the code tidy. .

  • Writing template code

In order to facilitate the management of our template files, you can place them under thepagesfolder, Create a new template file, which stores the written template; we need to use the tagtemplateto wrap the code, and add anameattribute to it. Of course, we must also write the corresponding style, and There is no difference in the normal way of writing styles.

The newly created template file can only store thewxmlandwxssfiles of the template. Currently, putting other file types in the template file of the mini program does not work. It cannot be reused, although no error is reported, such asjsfiles. The

templatetag is just a placeholder, telling the compiler that this is where the template code is loaded. When the page is compiled, the tag disappears, so it is necessary to respond to events with the template file. , we need to wrap the template file with a tag that can add events in the area where the template file is loaded, such as:view / block

## template template code

  • Use the template code

to write the template Code, how to use it where template code needs to be loaded?

First of all, the template code is in other folders. To use it, you must import the template file.

Generally introduce it at the beginning of the file corresponding to the template file to be imported:

// 在对应的wxml文件中开头引入  // 在对应的wxss文件中开头引入,注意末尾的分号 @import '模版wxss文件路径' ;
Then in the

wxmlfile that introduces the template file, use