初步学习小程序模板,就把过程写一下了.

1.在app.json里面注册temlate/public,生成模板wxml,wxss等系列页面

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

2.注册模板

<1>无数据传参的模板

<template name="hello">
  <view>hello world!</view>
</template>

<2>带数据传参的模板

<template name="hello2">
  <view wx:for='{{list}}' wx:key="{{key}}">hello world!{{item.name}}</view>
</template>

3.模板的使用

<1>引入模板页面

<import src="../template/hello/hello.wxml"/>

<2>使用模板

<view>
  <template is="hello" ></template>
  <template is="hello2" data="{{list}}"></template>
  
</view>

注意:

1.引用的template传入的data参数名字(data="{{list}}")要与注册时template使用的(wx:for="{{list}}" 时)的参数名字相同

2.template的data是有作用域的,外部参数通过data传入注册的template里面,只作用与template局部,可重复引用

 

  

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄