What is the template?
As the name suggests, a template is a public resource that can be applied on a page
What is the role?
Reduce duplication of code, the code will be more concise, different pages can use templates, can improve development efficiency
how to use?
- Template definition: use name as the template name
<template name="list-item">
......内容........
</template>
- Template use: use is = "name" to declare the template to be used, and then pass in the data required by the template
<template is="list-item" data="{{...item}}" />
-
Reference: <import src = 'target path' />
import有作用域概念,不能传递import.比如A中import B,B import C,这时A是不能使用C的
- Reference: <include src = 'target path' />
Equivalent to directly copying the code in the template except template
- Incoming data is rendered
using the three-point expanded data ...
<view wx:for="{{result}}" wx:key="index" data-index="{{index}}">
<template is="list-item" data="{{...item}}" />
</view>
You can use a for loop by adding a parent view externally to output all data, and by binding the index, you can operate on each item